Plette

2.1.0 · active · verified Thu Apr 16

Plette is a Python library that provides structured models for parsing, generating, and validating Pipfile and Pipfile.lock files. It allows developers to programmatically interact with project dependencies in a structured manner. The current version is 2.1.0, and it maintains a regular release cadence with significant updates, including a major version bump from v1 to v2.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load Pipfile and Pipfile.lock content from strings using `io.StringIO`, access their structured properties, and then modify and dump a Pipfile back to a string. It shows how to retrieve the required Python version from Pipfile, list packages, and access specific dependency versions from Lockfile.

import io
from plette import Pipfile, Lockfile

# Example Pipfile content
pipfile_content = '''
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"

[dev-packages]
pytest = "*"

[requires]
python_version = "3.8"
'''

# Example Pipfile.lock content (simplified for demonstration)
lockfile_content = '''
{
    "_meta": {
        "hash": {
            "sha256": "some_hash"
        },
        "requires": {
            "python_version": "3.8"
        }
    },
    "default": {
        "requests": {
            "hashes": [
                "sha256:hash1",
                "sha256:hash2"
            ],
            "version": "==2.28.1"
        }
    },
    "develop": {
        "pytest": {
            "hashes": [
                "sha256:hash3",
                "sha256:hash4"
            ],
            "version": "==7.1.2"
        }
    }
}
'''

# Load Pipfile
with io.StringIO(pipfile_content) as f:
    pipfile = Pipfile.load(f)

print(f"Pipfile Python Version: {pipfile.requires.python_version}")
print(f"Pipfile Packages: {list(pipfile.packages.keys())}")

# Load Lockfile
with io.StringIO(lockfile_content) as f:
    lockfile = Lockfile.load(f)

print(f"Lockfile requests version: {lockfile.default['requests']['version']}")
print(f"Lockfile meta hash: {lockfile._meta['hash']['sha256']}")

# Modify and dump (Pipfile example)
pipfile.packages['rich'] = '==12.0.0'
with io.StringIO() as f:
    pipfile.dump(f)
    print("\nModified Pipfile content:")
    print(f.getvalue())

view raw JSON →