{"id":46644316,"url":"https://github.com/kitschpatrol/read-pyproject","last_synced_at":"2026-03-08T04:07:44.277Z","repository":{"id":341064851,"uuid":"1168283785","full_name":"kitschpatrol/read-pyproject","owner":"kitschpatrol","description":"Parse and normalize pyproject.toml metadata into strictly typed JavaScript objects.","archived":false,"fork":false,"pushed_at":"2026-02-27T21:08:43.000Z","size":604,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-27T23:47:59.034Z","etag":null,"topics":["npm-package","pep-518","pyproject","python","toml"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kitschpatrol.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-27T07:57:54.000Z","updated_at":"2026-02-27T21:08:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kitschpatrol/read-pyproject","commit_stats":null,"previous_names":["kitschpatrol/read-pyproject"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kitschpatrol/read-pyproject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitschpatrol%2Fread-pyproject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitschpatrol%2Fread-pyproject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitschpatrol%2Fread-pyproject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitschpatrol%2Fread-pyproject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kitschpatrol","download_url":"https://codeload.github.com/kitschpatrol/read-pyproject/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitschpatrol%2Fread-pyproject/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30243525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm-package","pep-518","pyproject","python","toml"],"created_at":"2026-03-08T04:07:43.819Z","updated_at":"2026-03-08T04:07:44.268Z","avatar_url":"https://github.com/kitschpatrol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +--\u003e\n\n\u003c!-- title --\u003e\n\n# read-pyproject\n\n\u003c!-- /title --\u003e\n\n\u003c!-- badges --\u003e\n\n[![NPM Package read-pyproject](https://img.shields.io/npm/v/read-pyproject.svg)](https://npmjs.com/package/read-pyproject)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\u003c!-- /badges --\u003e\n\n\u003c!-- short-description --\u003e\n\n**Parse and normalize pyproject.toml metadata into strictly typed JavaScript objects.**\n\n\u003c!-- /short-description --\u003e\n\n## Overview\n\nA typed [`pyproject.toml`](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) reader for Node.js.\n\nHighlights:\n\n- **Typed output**\\\n  The returned object is deeply typed via Zod schema inference, giving you autocomplete and type safety for `[project]`, `[build-system]`, `[dependency-groups]`, and 30+ `[tool.*]` sections.\n\n- **Normalization**\\\n  The mess of `kebab-case`, `snake_case`, and `PascalCase` keys are converted to `camelCase` in the output by default, and some other fields (like `license` and `readme` values) are sensibly normalized.\n\n- **Flexibly strict**\\\n  Control how unknown keys are handled with three modes: `'passthrough'` (default, keeps everything), `'strip'` (silently removes unknown keys), or `'error'` (throws on unknown keys).\n\n- **Broad tool coverage**\\\n  Typed schemas for 30+ common `[tool.*]` sections. Unrecognized tools pass through as `unknown` by default.\n\nNote that this library currently only _reads_, it does not write changes back to the `.toml` file.\n\n## Getting started\n\n### Dependencies\n\n[Node](https://nodejs.org/) 20.17.0+\n\n### Installation\n\n```sh\nnpm install read-pyproject\n```\n\n### Quick start\n\n```ts\nimport { readPyproject } from 'read-pyproject'\n\nconst pyproject = await readPyproject('/path/to/project')\n\nconsole.log(pyproject.project?.name) // Normalized PEP 503 name\nconsole.log(pyproject) // The rest of the object...\n```\n\nOr parse a TOML string directly:\n\n```ts\nimport { parsePyproject } from 'read-pyproject'\n\nconst toml = `\n[project]\nname = \"my-package\"\nversion = \"1.0.0\"\n`\n\nconst pyproject = parsePyproject(toml)\n```\n\n## Usage\n\n### API\n\n#### `readPyproject(pathOrDirectory?, options?)`\n\nRead, parse, validate, and normalize a `pyproject.toml` file.\n\n##### Parameters\n\n- `pathOrDirectory` — A file path or directory. If a directory, appends `/pyproject.toml`. Defaults to `process.cwd()`.\n- `options` — Optional configuration object:\n  - `camelCase` — Convert keys to camelCase (`true` by default). Set to `false` to get raw TOML keys.\n  - `unknownKeyPolicy` — How to handle unknown keys: `'passthrough'` (default), `'strip'`, or `'error'`.\n\n##### Returns\n\n- `Promise\u003cPyprojectData\u003e` when `camelCase` is `true` (default)\n- `Promise\u003cRawPyprojectData\u003e` when `camelCase` is `false`\n\nThe return type is inferred from the `camelCase` option via function overloads.\n\n##### Throws\n\n`PyprojectError` on missing files, invalid TOML, or validation failures (in `'error'` mode).\n\n##### Examples\n\n```ts\nimport { readPyproject } from 'read-pyproject'\n\n// Read from current directory (camelCase keys by default)\nawait readPyproject()\n\n// Read from a specific file\nawait readPyproject('/path/to/pyproject.toml')\n\n// Read from a directory\nawait readPyproject('/path/to/project')\n\n// Get raw TOML keys (no camelCase conversion)\nconst raw = await readPyproject('/path/to/project', { camelCase: false })\nraw['build-system']?.['build-backend'] // Raw kebab-case keys\n\n// Reject unknown keys\nawait readPyproject('/path/to/project', { unknownKeyPolicy: 'error' })\n\n// Strip unknown keys from the output\nawait readPyproject('/path/to/project', { unknownKeyPolicy: 'strip' })\n```\n\n#### `parsePyproject(content, options?)`\n\nParse, validate, and normalize a `pyproject.toml` content string. This is the synchronous counterpart to `readPyproject` — it accepts a TOML string instead of reading from the filesystem.\n\n##### Parameters\n\n- `content` — A `pyproject.toml` content string.\n- `options` — Optional configuration object:\n  - `camelCase` — Convert keys to camelCase (`true` by default). Set to `false` to get raw TOML keys.\n  - `unknownKeyPolicy` — How to handle unknown keys: `'passthrough'` (default), `'strip'`, or `'error'`.\n\n##### Returns\n\n- `PyprojectData` when `camelCase` is `true` (default)\n- `RawPyprojectData` when `camelCase` is `false`\n\nThe return type is inferred from the `camelCase` option via function overloads.\n\n##### Throws\n\n`PyprojectError` on invalid TOML or validation failures (in `'error'` mode).\n\n##### Examples\n\n```ts\nimport { parsePyproject } from 'read-pyproject'\n\n// Parse a TOML string (camelCase keys by default)\nconst pyproject = parsePyproject('[project]\\nname = \"my-package\"')\n\n// Get raw TOML keys (no camelCase conversion)\nconst raw = parsePyproject(tomlString, { camelCase: false })\n\n// Reject unknown keys\nparsePyproject(tomlString, { unknownKeyPolicy: 'error' })\n```\n\n#### `PyprojectError`\n\nCustom error class thrown for file read errors, TOML parse errors, and validation failures. Includes a `filePath` property for context.\n\n#### `setLogger(logger?)`\n\nInject a custom logger. Accepts a [LogLayer](https://github.com/theogravity/loglayer) instance or a `Console`-like object.\n\n### Normalization\n\n- All kebab-case, snake_case, and PascalCase keys in the TOML are converted to camelCase in the output by default. Pass `{ camelCase: false }` to disable this and receive raw TOML keys instead.\n\n- `project.name` is normalized per [PEP 503](https://peps.python.org/pep-0503/#normalized-names) (lowercased, runs of `[-_.]+` collapsed to a single `-`). The original name is available as `project.rawName`. This normalization is always applied regardless of the `camelCase` option.\n\n- `project.readme` is normalized to a string when the readme is file-based (`\"README.md\"` stays as-is, `{ file: \"README.md\", content-type: \"...\" }` collapses to `\"README.md\"`). Inline-text readmes (`{ text: \"...\", content-type: \"...\" }`) are kept as a `{ text, contentType? }` object.\n\n- `project.license` is normalized from an SPDX string (`\"MIT\"`) to `{ spdx }`, validated and corrected via [spdx-correct](https://github.com/jslicense/spdx-correct.js). Legacy table-form licenses (`{ file }` or `{ text }`) pass through as-is.\n\n### Supported `[tool.*]` sections\n\nThe following tools have typed schemas:\n\nautopep8, bandit, black, bumpversion, check-wheel-contents, cibuildwheel, codespell, comfy, commitizen, coverage, dagster, distutils, docformatter, flake8, flit, hatch, isort, jupyter-releaser, mypy, pdm, pixi, poe, poetry, pydocstyle, pylint, pyright, pytest, ruff, setuptools, setuptools_scm, tbump, towncrier, uv, yapf\n\nUnknown tools pass through as `unknown` by default.\n\n## Background\n\n### Motivation\n\nI wanted something like [read-pkg](https://github.com/sindresorhus/read-pkg) or [pkg-types](https://github.com/unjs/pkg-types), but for `pyproject.toml` files.\n\nIt's a bit strange to work across language ecosystems like this, but I had occasion to do so for some other Node-based projects related to project metadata extraction, specifically [@kitschpatrol/codemeta](https://github.com/kitschpatrol/codemeta) and [metascope](https://github.com/kitschpatrol/metascope).\n\n### Implementation notes\n\nThe project consists of a number of [Zod](https://zod.dev) schemas responsible for validating and normalizing data found in a `pyproject.toml`. Schemas output raw TOML keys; camelCase conversion is handled centrally by a recursive `deepCamelCaseKeys` function that knows which paths contain user-defined record keys (like package names or file paths) and skips those. Type-level camelCase conversion uses [`CamelCasedPropertiesDeep`](https://github.com/sindresorhus/type-fest) from `type-fest`, and function overloads ensure the return type matches the `camelCase` option.\n\nForcing the rather dynamic and extensible data structure found in `pyproject.toml` into a TypeScript straightjacket is likely futile, but an LLM makes the project at least somewhat tractable.\n\n## Maintainers\n\n@kitschpatrol\n\n## Slop factor\n\n_High._\n\nAn initial human-crafted specification was implemented by LLM. The output has been subject to only moderate post-facto human scrutiny.\n\n\u003c!-- contributing --\u003e\n\n## Contributing\n\n[Issues](https://github.com/kitschpatrol/read-pyproject/issues) and pull requests are welcome.\n\n\u003c!-- /contributing --\u003e\n\n\u003c!-- license --\u003e\n\n## License\n\n[MIT](license.txt) © Eric Mika\n\n\u003c!-- /license --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitschpatrol%2Fread-pyproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkitschpatrol%2Fread-pyproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitschpatrol%2Fread-pyproject/lists"}