{"id":9185,"library":"plette","title":"Plette","description":"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.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/sarugaku/plette","tags":["dependency management","Pipfile","Pipfile.lock","parsing","serialization"],"install":[{"cmd":"pip install plette","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Directly import the class from the package for clarity and to avoid potential naming conflicts with the top-level 'plette' module.","wrong":"import plette.Pipfile_deprecated","symbol":"Pipfile","correct":"from plette import Pipfile"},{"note":"Directly import the class from the package.","wrong":"import plette.Lockfile_util","symbol":"Lockfile","correct":"from plette import Lockfile"}],"quickstart":{"code":"import io\nfrom plette import Pipfile, Lockfile\n\n# Example Pipfile content\npipfile_content = '''\n[[source]]\nurl = \"https://pypi.org/simple\"\nverify_ssl = true\nname = \"pypi\"\n\n[packages]\nrequests = \"*\"\n\n[dev-packages]\npytest = \"*\"\n\n[requires]\npython_version = \"3.8\"\n'''\n\n# Example Pipfile.lock content (simplified for demonstration)\nlockfile_content = '''\n{\n    \"_meta\": {\n        \"hash\": {\n            \"sha256\": \"some_hash\"\n        },\n        \"requires\": {\n            \"python_version\": \"3.8\"\n        }\n    },\n    \"default\": {\n        \"requests\": {\n            \"hashes\": [\n                \"sha256:hash1\",\n                \"sha256:hash2\"\n            ],\n            \"version\": \"==2.28.1\"\n        }\n    },\n    \"develop\": {\n        \"pytest\": {\n            \"hashes\": [\n                \"sha256:hash3\",\n                \"sha256:hash4\"\n            ],\n            \"version\": \"==7.1.2\"\n        }\n    }\n}\n'''\n\n# Load Pipfile\nwith io.StringIO(pipfile_content) as f:\n    pipfile = Pipfile.load(f)\n\nprint(f\"Pipfile Python Version: {pipfile.requires.python_version}\")\nprint(f\"Pipfile Packages: {list(pipfile.packages.keys())}\")\n\n# Load Lockfile\nwith io.StringIO(lockfile_content) as f:\n    lockfile = Lockfile.load(f)\n\nprint(f\"Lockfile requests version: {lockfile.default['requests']['version']}\")\nprint(f\"Lockfile meta hash: {lockfile._meta['hash']['sha256']}\")\n\n# Modify and dump (Pipfile example)\npipfile.packages['rich'] = '==12.0.0'\nwith io.StringIO() as f:\n    pipfile.dump(f)\n    print(\"\\nModified Pipfile content:\")\n    print(f.getvalue())\n","lang":"python","description":"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."},"warnings":[{"fix":"Use the `.get()` method or `try-except` blocks to handle potentially missing keys gracefully. For example: `pipfile.get('non_existent_section', {})`.","message":"Accessing missing sections or keys in Pipfile or Lockfile models directly (e.g., `pipfile.non_existent_section`) will raise `KeyError` or `AttributeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer higher-level `plette` APIs for modifications, if available, or regenerate the lockfile using `pipenv lock` if using Pipenv, to ensure integrity and correct hashing.","message":"While canonical names like `pipfile.source` and `lockfile._meta` are still available, direct manipulation of the `_meta` section of a `Lockfile` is generally discouraged.","severity":"deprecated","affected_versions":"v2.0.0+"},{"fix":"Review your code for direct property access, especially for nested structures or alias usage. Consult the official `plette` GitHub repository for any unlisted breaking changes. Prioritize using official loading/dumping methods and avoid direct dictionary manipulation where possible.","message":"Major version `2.0.0` was released. While specific migration notes for `plette` are not extensively documented, changes between major versions often involve API refinements. Users upgrading from v1.x may encounter breaking changes in how certain properties are accessed or how objects are constructed.","severity":"breaking","affected_versions":"v1.x to v2.x"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Use dictionary-style `.get()` method to safely access sections, providing a default value if the section might be missing. E.g., `pipfile.get('missing_section', {})`.","cause":"Attempting to access a non-existent top-level section in a Pipfile object directly as an attribute.","error":"AttributeError: 'Pipfile' object has no attribute 'missing_section'"},{"fix":"Verify the package name is correct and present in the `Pipfile.lock`. Use `lockfile.default.get('some-package')` to handle cases where the package might not exist without raising an error.","cause":"The specified package 'some-package' is not found within the 'default' dependencies section of the loaded Lockfile.","error":"KeyError: 'some-package' when accessing lockfile.default['some-package']"},{"fix":"Access specific sections of the `Lockfile` (e.g., `lockfile.default`, `lockfile.develop`) and iterate over those dictionaries. For example, `for package, details in lockfile.default.items(): ...`.","cause":"Trying to iterate directly over a `Lockfile` object, which is not designed to be iterable.","error":"TypeError: argument of type 'Lockfile' is not iterable"}]}