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 poetry-plugin-lock-filter

Or install it as a normal Python package:

pip install poetry-plugin-lock-filter

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.3

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.3
File Size Uploaded Provenance Actions
poetry_plugin_lock_filter-0.1.3.tar.gz 12.3 kB With provenance Details for poetry_plugin_lock_filter-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 23.4 kB

Release files / poetry_plugin_lock_filter-0.1.3.tar.gz

Download URL poetry_plugin_lock_filter-0.1.3.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a04b2f15f613fcce3febec0e26f1bc3bb06d8c7a6f65885abd24fab2fea4ec38
BLAKE2b-256 checksum
How to use checksums
f4e4b002ca7392a32a09915cf107be55149c465017e5aeb9da8e13617a574c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

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

Download URL poetry_plugin_lock_filter-0.1.3-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccb37a83fea6b899d268ed9ceb50e3676dd83d63315735c51a02c336ced01281
BLAKE2b-256 checksum
How to use checksums
4c0bb0d1d71b3502fa678362279e22ebb5e21d9daed136cdec560a543c3c7664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for poetry-plugin-lock-filter 0.1.3

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for poetry_plugin_lock_filter-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

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