Skip to main content

poetry-plugin-lock-filter

A Poetry 2.x plugin and standalone CLI for creating marker-specific lock files.

Poetry writes a universal poetry.lock that contains every marker branch. Installation evaluates those markers at runtime, but the lock file itself remains broad. This project post-processes a Poetry lock file and keeps only packages whose markers match a selected target environment.

Why

Given dependencies such as:

[tool.poetry.dependencies]
linux-only = { version = "1.0", markers = "sys_platform == 'linux'" }
windows-only = { version = "2.0", markers = "sys_platform == 'win32'" }

Poetry 2.4.1 writes both packages to poetry.lock, even when only one branch is active on the current machine.

poetry install selects the correct packages, but tools that read poetry.lock directly often see both branches. This plugin produces a clean, target-specific lock file without changing the original.

Features

  • Poetry plugin command: poetry filter-lock
  • Standalone command: poetry-lock-filter
  • Presets for common target environments
  • Repeated --env KEY=VALUE overrides
  • Main-group filtering by default
  • Optional-package exclusion by default
  • Dependency pruning so retained packages only reference retained dependencies
  • JSON report output
  • Original poetry.lock is preserved by default

Installation

Install as a Poetry plugin:

poetry self add git+https://github.com/RealDioBrando/poetry-plugin-lock-filter.git

Or install it as a normal Python package:

pip install git+https://github.com/RealDioBrando/poetry-plugin-lock-filter.git

Poetry plugin usage

Run inside a Poetry project:

poetry filter-lock

This reads the project’s poetry.lock and writes:

poetry.target.lock

The default target environment is:

Linux
aarch64
CPython 3.11

Standalone usage

poetry-lock-filter \
  --project /path/to/project \
  --output poetry.target.lock \
  --preset linux-aarch64-cp311

If --project is omitted, the command uses the current directory.

Target presets

  • current
  • linux-aarch64-cp311
  • linux-x86_64-cp311
  • windows-x86_64-cp311

Override individual environment markers:

poetry filter-lock \
  --preset linux-aarch64-cp311 \
  --env python_version=3.11 \
  --env platform_machine=aarch64

Use --preset current to filter for the machine running the command.

Options

--output PATH            Output lock file; default poetry.target.lock
--preset NAME            Target environment preset
--env KEY=VALUE          Override a marker environment value; repeatable
--group NAME             Dependency group to retain; default main
--include-optional       Keep optional packages
--report PATH            Write a JSON filtering report
--no-check               Do not require a fresh lock file

The standalone command also supports:

--project PATH           Poetry project directory
--lock PATH              Explicit lock file path

Example report

{
  "status": "success",
  "input": "poetry.lock",
  "output": "poetry.target.lock",
  "group": "main",
  "target_environment": {
    "python_version": "3.11",
    "sys_platform": "linux",
    "platform_machine": "aarch64"
  },
  "included_packages": ["linux-only"],
  "excluded_packages": [
    {
      "package": "windows-only",
      "reason": "marker",
      "marker": "sys_platform == \"win32\""
    }
  ]
}

Dependency pruning

The filter also removes dependency references from retained packages when the referenced package was excluded.

For example, if linux-only depends on linux-helper, and both match the target environment, both are retained. If linux-only has a Windows-only dependency, that dependency edge is removed from the filtered lock.

Compatibility

  • Python 3.11 or newer
  • Poetry 2.1 or newer
  • Poetry lock format 2.1 or newer

Development

python -m venv .venv
.venv/bin/python -m pip install -e .[dev]
.venv/bin/python -m unittest discover -s tests -v

License

MIT

  • poetry-plugin-export exports a Poetry lock file to requirements formats, but does not create a marker-filtered lock file.
  • poetry-lock-package turns a lock file into a pinned package, but does not filter packages by environment markers.
  • ofiuco provides Bazel rules for cross-platform Poetry lock files, but is not a Poetry plugin or standalone marker filter.

Metadata

Release files for poetry-plugin-lock-filter 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poetry-plugin-lock-filter 0.1.0
File Size Uploaded Provenance Actions
poetry_plugin_lock_filter-0.1.0.tar.gz 12.8 kB Without provenance Details for poetry_plugin_lock_filter-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for poetry-plugin-lock-filter 0.1.0
File Interpreter ABI Platform Actions
poetry_plugin_lock_filter-0.1.0-py3-none-any.whl Python 3 none any Details for poetry_plugin_lock_filter-0.1.0-py3-none-any.whl

Total release size: 24.0 kB

Release files / poetry_plugin_lock_filter-0.1.0.tar.gz

Download URL poetry_plugin_lock_filter-0.1.0.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d9fc313c53a21e2a94d5c6cec368ca19464e38aa05ac46446048cdc05b91ed67
BLAKE2b-256 checksum
How to use checksums
125a3ede055d7e1ba48606c8181fe969c7838947aafb7f98551c690ce10f5280
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release files / poetry_plugin_lock_filter-0.1.0-py3-none-any.whl

Download URL poetry_plugin_lock_filter-0.1.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f989a88a59d88bc58c4c4273722c2e4be38a86dde0ef68b5ec785a219dfeb3a0
BLAKE2b-256 checksum
How to use checksums
3113ef99d79fb194692f5ea72949d225a74858e8383d6e40ab41ef764592de01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Security for poetry-plugin-lock-filter 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page