|
| 1 | +--- |
| 2 | +title: Exporting a lockfile |
| 3 | +description: Exporting a lockfile to different formats |
| 4 | +--- |
| 5 | + |
| 6 | +# Exporting a lockfile |
| 7 | + |
| 8 | +uv can export a lockfile to different formats for integration with other tools and workflows. The |
| 9 | +`uv export` command supports multiple output formats, each suited to different use cases. |
| 10 | + |
| 11 | +For more details on lockfiles and how they're created, see the [project layout](./layout.md) and |
| 12 | +[locking and syncing](./sync.md) documentation. |
| 13 | + |
| 14 | +## Overview of export formats |
| 15 | + |
| 16 | +uv supports three export formats: |
| 17 | + |
| 18 | +- `requirements.txt`: The traditional pip-compatible |
| 19 | + [requirements file format](https://pip.pypa.io/en/stable/reference/requirements-file-format/). |
| 20 | +- `pylock.toml`: The standardized Python lockfile format defined in |
| 21 | + [PEP 751](https://peps.python.org/pep-0751/). |
| 22 | +- `CycloneDX`: An industry-standard [Software Bill of Materials (SBOM)](https://cyclonedx.org/) |
| 23 | + format. |
| 24 | + |
| 25 | +The format can be specified with the `--format` flag: |
| 26 | + |
| 27 | +```console |
| 28 | +$ uv export --format requirements.txt |
| 29 | +$ uv export --format pylock.toml |
| 30 | +$ uv export --format cyclonedx1.5 |
| 31 | +``` |
| 32 | + |
| 33 | +!!! tip |
| 34 | + |
| 35 | + By default, `uv export` prints to stdout. Use `--output-file` to write to a file for any format: |
| 36 | + |
| 37 | + ```console |
| 38 | + $ uv export --format requirements.txt --output-file requirements.txt |
| 39 | + $ uv export --format pylock.toml --output-file pylock.toml |
| 40 | + $ uv export --format cyclonedx1.5 --output-file sbom.json |
| 41 | + ``` |
| 42 | + |
| 43 | +## `requirements.txt` format |
| 44 | + |
| 45 | +The `requirements.txt` format is the most widely supported format for Python dependencies. It can be |
| 46 | +used with `pip` and other Python package managers. |
| 47 | + |
| 48 | +### Basic usage |
| 49 | + |
| 50 | +```console |
| 51 | +$ uv export --format requirements.txt |
| 52 | +``` |
| 53 | + |
| 54 | +The generated `requirements.txt` file can then be installed via `uv pip install`, or with other |
| 55 | +tools like `pip`. |
| 56 | + |
| 57 | +!!! note |
| 58 | + |
| 59 | + In general, we recommend against using both a `uv.lock` and a `requirements.txt` file. The |
| 60 | + `uv.lock` format is more powerful and includes features that cannot be expressed in |
| 61 | + `requirements.txt`. If you find yourself exporting a `uv.lock` file, consider opening an issue |
| 62 | + to discuss your use case. |
| 63 | + |
| 64 | +## `pylock.toml` format |
| 65 | + |
| 66 | +[PEP 751](https://peps.python.org/pep-0751/) defines a TOML-based lockfile format for Python |
| 67 | +dependencies. uv can export your project's dependency lockfile to this format. |
| 68 | + |
| 69 | +### Basic usage |
| 70 | + |
| 71 | +```console |
| 72 | +$ uv export --format pylock.toml |
| 73 | +``` |
| 74 | + |
| 75 | +## CycloneDX SBOM format |
| 76 | + |
| 77 | +uv can export your project's dependency lockfile as a Software Bill of Materials (SBOM) in CycloneDX |
| 78 | +format. SBOMs provide a comprehensive inventory of all software components in your application, |
| 79 | +which is useful for security auditing, compliance, and supply chain transparency. |
| 80 | + |
| 81 | +!!! important |
| 82 | + |
| 83 | + Support for exporting to CycloneDX is in [preview](../preview.md), and may change in any future release. |
| 84 | + |
| 85 | +### What is CycloneDX? |
| 86 | + |
| 87 | +[CycloneDX](https://cyclonedx.org/) is an industry-standard format for creating Software Bill of |
| 88 | +Materials. CycloneDX is machine readable and widely supported by security scanning tools, |
| 89 | +vulnerability databases, and Software Composition Analysis (SCA) platforms. |
| 90 | + |
| 91 | +### Basic usage |
| 92 | + |
| 93 | +To export your project's lockfile as a CycloneDX SBOM: |
| 94 | + |
| 95 | +```console |
| 96 | +$ uv export --format cyclonedx1.5 |
| 97 | +``` |
| 98 | + |
| 99 | +This will generate a JSON-encoded CycloneDX v1.5 document containing your project and all of its |
| 100 | +dependencies. |
| 101 | + |
| 102 | +### SBOM Structure |
| 103 | + |
| 104 | +The generated SBOM follows the |
| 105 | +[CycloneDX specification](https://cyclonedx.org/specification/overview/). uv also includes the |
| 106 | +following custom properties on components: |
| 107 | + |
| 108 | +- `uv:package:marker`: Environment markers (e.g., `python_version >= "3.8"`) |
| 109 | +- `uv:workspace:path`: Relative path for workspace members |
| 110 | + |
| 111 | +## Next steps |
| 112 | + |
| 113 | +To learn more about lockfiles and exporting, see the [locking and syncing](./sync.md) documentation |
| 114 | +and the [command reference](../../reference/cli.md#uv-export). |
| 115 | + |
| 116 | +Or, read on to learn how to |
| 117 | +[build and publish your project to a package index](../../guides/package.md). |
0 commit comments