Skip to main content

poetry-auto-export

Automatically export dependencies to requirements.txt on every poetry lock

This plugin enables you to keep a requirements.txt file always up to date with your poetry.lock file. This is helpful if you want to use pip to install your dependencies somewhere, e.g.

  • in CI/CD environments
  • in docker containers

Usage

Add plugin configuration to your pyproject.toml. The options follow arguments for poetry export.

[tool.poetry-auto-export]
output = "requirements.txt"
without_hashes = true
without = ["dev"]

Then, run poetry commands as usual:

poetry lock

The requirements.txt file will be updated automatically.

The supported commands are:

  • lock
  • update
  • add
  • remove

Detect lock file changes

Suppose you're working on a project with CI/CD and several contributors. You want the CI/CD to depend on the requirements.txt file created by poetry-auto-export, but you need to make sure everyone updates the requirements.txt file correctly.

To make this easy, poetry-auto-export puts a SHA1 hash in a comment on top of requirements.txt file. In CI/CD you can quickly compute the hash and compare that with the comment without installing poetry or any other dependencies.

Here is an example python script that does this:

import hashlib
from pathlib import Path

lock_hash = hashlib.sha1(Path("poetry.lock").read_bytes()).hexdigest()
first_line = Path("requirements.txt").read_text().split("\n")[0]

if first_line != f"# poetry.lock hash: {lock_hash}":
    raise ValueError(
        "requirements.txt is out of date, use the `poetry-auto-export` plugin to update it!"
    )

A more fancy version of the above script is shipped with this package as check_requirements_file.py. You can also download it from the Github repository directly, e.g.

curl -O https://raw.githubusercontent.com/Ddedalus/poetry-auto-export/refs/heads/main/poetry_auto_export/check_requirements_file.py

Or pipe straight into python, for a quick one-liner:

curl -sSL https://raw.githubusercontent.com/Ddedalus/poetry-auto-export/refs/heads/main/poetry_auto_export/check_requirements_file.py | python3 -

Creating multiple export files

If you need to create multiple requirements files, e.g. dev-requirements.txt and prod-requirements.txt, use the following syntax:

[[tool.poetry-auto-export.exports]]
output = "dev-requirements.txt"
without = ["prod"]

[[tool.poetry-auto-export.exports]]
output = "prod-requirements.txt"
without = ["dev"]

Installation

This is a poetry plugin, so it's meant to be installed inside the global poetry environment, not your project environment like regular pacakges. See poetry's docs.

There are three ways of doing so.

The pipx way

If you are using pipx already, that's easy:

pipx inject poetry poetry-auto-export

The pip way

Otherwise, you can use the pip that comes with poetry. The difficulty is finding that pip! It's not the same one you get with poetry run pip. Here is a best effort guess:

On Linux:

~/.local/share/pypoetry/venv/bin/pip install poetry-auto-export

On Windows:

%APPDATA%\pypoetry\venv\bin\pip install poetry-auto-export

The poetry way

For some reason, this is discouraged by poetry.

poetry self add poetry-auto-export

Roadmap and contributing

The primary goal of the project is to make it more convenient to work with poetry projects in CI/CD and docker. Contributions towards this goal are welcome!

Roadmap:

  • more unit tests for the plugin
  • integration tests for the plugin
  • proper configuration parsing (note: typed dict and dataclasses can't support the with option, since it's a python keyword)
  • schema or exhaustive documentation of the supported configuration options

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poetry_auto_export-0.4.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poetry_auto_export-0.4.3-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file poetry_auto_export-0.4.3.tar.gz.

File metadata

  • Download URL: poetry_auto_export-0.4.3.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.3 CPython/3.12.3 Linux/6.17.0-1022-azure

File hashes

Hashes for poetry_auto_export-0.4.3.tar.gz
Algorithm Hash digest
SHA256 f7599f2834142f379a37a9276d1f06705d5946910afa5f9892c9ac44b7e52a9c
MD5 9947c7ead244eee0951f29d1ccdad0af
BLAKE2b-256 c2e0c74f2bff748536c250245e7e4dfedbcbd04db0165f87f7e7a133aa13ad18

See more details on using hashes here.

File details

Details for the file poetry_auto_export-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: poetry_auto_export-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.3 CPython/3.12.3 Linux/6.17.0-1022-azure

File hashes

Hashes for poetry_auto_export-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e0d4149efb2c5bbaa87aad2144ce284380bb452df9395c1bdcaaacbc5c10403d
MD5 2f40b12e9862d51ce48c8819850ca583
BLAKE2b-256 a60cea3b3dfa8d3113bd476f87902167ddebf32d8285dd819ae4415c3c2f780e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 files

0.4.2

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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