Pipfile File Format Specification Library

0.0.2 · active · verified Thu Apr 16

The `pipfile` library serves as the canonical reference and parsing implementation for the Pipfile and Pipfile.lock file formats. It is a low-level library primarily intended for use by other tools (such as Pipenv) to programmatically read, write, and manipulate these dependency definition files. The current version is 0.0.2, and its release cadence is very infrequent, reflecting its role as a stable specification parser rather than a frequently updated application.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse Pipfile and Pipfile.lock contents using the `Pipfile` and `PipfileLock` classes. You can parse from a string using `.parse()` or from a file path using `.load()` (e.g., `Pipfile.load('Pipfile')`). It then shows how to access the various sections and package definitions within these objects.

import os
from pipfile import Pipfile, PipfileLock

# Example Pipfile content (simulating reading from a file)
pipfile_content = """
[packages]
requests = "*"
flask = {version = "==2.0.0", extras = ["dotenv"]}

[dev-packages]
pytest = "*"

[requires]
python_version = "3.9"
"""

# Parse a Pipfile from a string
# For real files, use Pipfile.load('/path/to/Pipfile')
pipfile = Pipfile.parse(pipfile_content)

print("--- Parsed Pipfile ---")
print(f"Python version required: {pipfile.requires.get('python_version')}")
print("Packages (default):")
for name, spec in pipfile.packages.items():
    print(f"  {name}: {spec}")
print("Dev Packages:")
for name, spec in pipfile.dev_packages.items():
    print(f"  {name}: {spec}")

# Example Pipfile.lock content (simulating reading from a file)
# (Simplified structure for demonstration)
lock_content = """
{
    "_meta": {
        "hash": {
            "sha256": "..."
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.9"
        }
    },
    "default": {
        "requests": {
            "hashes": ["sha256:..."],
            "version": "==2.28.1"
        },
        "flask": {
            "hashes": ["sha256:..."],
            "version": "==2.0.0"
        }
    },
    "develop": {
        "pytest": {
            "hashes": ["sha256:..."],
            "version": "==7.1.2"
        }
    }
}
"""

# Parse a Pipfile.lock from a string
# For real files, use PipfileLock.load('/path/to/Pipfile.lock')
pipfile_lock = PipfileLock.parse(lock_content)

print("\n--- Parsed Pipfile.lock ---")
print("Locked packages (default):")
for name, details in pipfile_lock.default_packages.items():
    print(f"  {name}: {details.get('version')}")

view raw JSON →