Skip to main content

Typed Python library for working with PEP 723 inline script metadata

Project description

PEPScript

CI PyPI Python License Coverage Docs

A Python library for parsing, validating, editing, and saving PEP 723 inline script metadata through a typed API.

  • Zero runtime dependencies (stdlib only)
  • Python 3.12+
  • Full type hints with py.typed

Installation

pip install pepscript

Usage

Read metadata from a script

from pepscript import PEPScript

script = PEPScript("my_script.py")
if script.has_metadata:
    print(script.meta.dependencies)
    print(script.meta.requires_python)

Edit and save

from pepscript import PEPScript

with PEPScript("my_script.py") as script:
    script.meta.add_dependency("httpx>=0.27")
    script.meta.set_requires_python(">=3.12")

Parse from a string

from pepscript import parse_script

script = parse_script("""\
# /// script
# dependencies = ["requests>=2.0"]
# requires-python = ">=3.12"
# ///
print("hello")
""")
print(script.meta.dependencies)  # ['requests>=2.0']

Access tool configuration

from pepscript import PEPScript

script = PEPScript("my_script.py")
if script.has_metadata:
    # Attribute access
    line_length = script.meta.config.tool.ruff.line_length
    # Item access (for keys with hyphens)
    setting = script.meta.config.tool["my-tool"]["some-setting"]

Validate metadata

from pepscript import PEPScript, MetadataValidationError

script = PEPScript("my_script.py", strict=False)
try:
    script.validate()
except MetadataValidationError as e:
    print(f"Invalid metadata: {e}")

Contributing

Setup

uv sync

Running checks

uv run pytest              # Tests
uv run ruff check .        # Lint
uv run ruff format .       # Format
uv run ty check .          # Type check

Versioning and releases

This project uses Semantic Versioning. The version is set in pyproject.toml. Release notes are generated automatically from Conventional Commits when a version tag is pushed.

To release:

  1. Update version in pyproject.toml
  2. Tag and push:
    git tag v0.1.1
    git push origin v0.1.1
    

Commit messages should follow Conventional Commits (fix:, feat:, feat!: for breaking changes).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pepscript-0.1.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pepscript-0.1.1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file pepscript-0.1.1.tar.gz.

File metadata

  • Download URL: pepscript-0.1.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pepscript-0.1.1.tar.gz
Algorithm Hash digest
SHA256 729e6894ab203c269919cd66797f8150988ad03a4d35fd8a464f8ad4091bb126
MD5 c1d3f2e69023d570fcceaca97d14291d
BLAKE2b-256 36427038f7425e914b124e0eb53f645f327bdf918c4cfd51b492f02f1cc36b50

See more details on using hashes here.

File details

Details for the file pepscript-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pepscript-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pepscript-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ae3f3790c5ffc4b8df7c0fa888da480131e09408ba76759321acf59cb3f29e2
MD5 465d2b4c8f79efb51ea76019b7691602
BLAKE2b-256 62f428797e274bf5a64f07362f9621ea56379b268259447b247fe3ff1a7d42a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page