Skip to content

Building and publishing a packageパッケージの構築と公開

uv supports building Python packages into source and binary distributions via uv build and uploading them to a registry with uv publish.uvは、uv buildを使用してPythonパッケージをソースおよびバイナリ配布に構築し、uv publishを使用してレジストリにアップロードすることをサポートしています。

Preparing your projectプロジェクトの準備

Before attempting to publish your project, you'll want to make sure it's ready to be packaged for distribution.プロジェクトを公開しようとする前に、配布用にパッケージ化する準備が整っていることを確認したいでしょう。

If your project does not include a [build-system] definition in the pyproject.toml, uv will not build it during uv sync operations in the project, but will fall back to the legacy setuptools build system during uv build.プロジェクトに[build-system]の定義がpyproject.tomlに含まれていない場合、uvはプロジェクト内のuv sync操作中にそれを構築せず、uv build中にレガシーsetuptoolsビルドシステムにフォールバックします。

We strongly recommend configuring a build system. Read more about build systems in the project configuration documentation.ビルドシステムの構成を強く推奨します。ビルドシステムについての詳細は、プロジェクト構成のドキュメントをお読みください。

Building your packageパッケージの構築

Build your package with uv build:uv buildを使用してパッケージを構築します:

$ uv build

By default, uv build will build the project in the current directory, and place the built artifacts in a dist/ subdirectory.デフォルトでは、uv buildは現在のディレクトリでプロジェクトを構築し、構築されたアーティファクトをdist/サブディレクトリに配置します。

Alternatively, uv build <SRC> will build the package in the specified directory, while uv build --package <PACKAGE> will build the specified package within the current workspace.または、uv build <SRC>は指定されたディレクトリでパッケージを構築し、uv build --package <PACKAGE>は現在のワークスペース内で指定されたパッケージを構築します。

Info情報

By default, uv build respects tool.uv.sources when resolving build dependencies from the build-system.requires section of the pyproject.toml. When publishing a package, we recommend running uv build --no-sources to ensure that the package builds correctly when tool.uv.sources is disabled, as is the case when using other build tools, like pypa/build.デフォルトでは、uv buildpyproject.tomlbuild-system.requiresセクションからビルド依存関係を解決する際にtool.uv.sourcesを尊重します。パッケージを公開する際には、tool.uv.sourcesが無効になっている場合(他のビルドツールを使用する場合、例えばpypa/build)にパッケージが正しくビルドされることを保証するために、uv build --no-sourcesを実行することをお勧めします。

Updating your versionバージョンの更新

The uv version command provides conveniences for updating the version of your package before you publish it. See the project docs for reading your package's version.uv versionコマンドは、パッケージを公開する前にバージョンを更新するための便利な機能を提供します。 パッケージのバージョンを読むためのプロジェクトドキュメントを参照してください

To update to an exact version, provide it as a positional argument:正確なバージョンに更新するには、位置引数として提供します:

$ uv version 1.0.0
hello-world 0.7.0 => 1.0.0

To preview the change without updating the pyproject.toml, use the --dry-run flag:pyproject.tomlを更新せずに変更をプレビューするには、--dry-runフラグを使用します:

$ uv version 2.0.0 --dry-run
hello-world 1.0.0 => 2.0.0
$ uv version
hello-world 1.0.0

To increase the version of your package semantics, use the --bump option:パッケージのセマンティクスのバージョンを上げるには、--bumpオプションを使用します:

$ uv version --bump minor
hello-world 1.2.3 => 1.3.0

The --bump option supports the following common version components: major, minor, patch, stable, alpha, beta, rc, post, and dev. When provided more than once, the components will be applied in order, from largest (major) to smallest (dev).--bumpオプションは、次の一般的なバージョンコンポーネントをサポートしています: major, minor, patch, stable, alpha, beta, rc, post, および dev。複数回提供された場合、コンポーネントは順番に適用されます(最も大きいものからmajor、最も小さいものへdev)。

You can optionally provide a numeric value with --bump <component>=<value> to set the resulting component explicitly:--bump <component>=<value>を使用して、結果のコンポーネントを明示的に設定するために数値をオプションで提供できます:

$ uv version --bump patch --bump dev=66463664
hello-world 0.0.1 => 0.0.2.dev66463664

To move from a stable to pre-release version, bump one of the major, minor, or patch components in addition to the pre-release component:安定版からプレリリース版に移行するには、プレリリースコンポーネントに加えて、メジャー、マイナー、またはパッチコンポーネントのいずれかをバンプします:

$ uv version --bump patch --bump beta
hello-world 1.3.0 => 1.3.1b1
$ uv version --bump major --bump alpha
hello-world 1.3.0 => 2.0.0a1

When moving from a pre-release to a new pre-release version, just bump the relevant pre-release component:プレリリースから新しいプレリリース版に移行する際は、関連するプレリリースコンポーネントをバンプするだけです:

$ uv version --bump beta
hello-world 1.3.0b1 => 1.3.0b2

When moving from a pre-release to a stable version, the stable option can be used to clear the pre-release component:プレリリースから安定版に移行する際、stableオプションを使用してプレリリースコンポーネントをクリアできます:

$ uv version --bump stable
hello-world 1.3.1b2 => 1.3.1

Info情報

By default, when uv version modifies the project it will perform a lock and sync. To prevent locking and syncing, use --frozen, or, to just prevent syncing, use --no-sync.デフォルトでは、uv versionがプロジェクトを変更すると、ロックと同期が行われます。ロックと同期を防ぐには、--frozenを使用するか、同期のみを防ぐには--no-syncを使用します。

Publishing your packageパッケージの公開

Note注意

A complete guide to publishing from GitHub Actions to PyPI can be found in the GitHub GuideGitHub ActionsからPyPIへの公開に関する完全なガイドは、GitHubガイドにあります。

Publish your package with uv publish:uv publishを使用してパッケージを公開します:

$ uv publish

Set a PyPI token with --token or UV_PUBLISH_TOKEN, or set a username with --username or UV_PUBLISH_USERNAME and password with --password or UV_PUBLISH_PASSWORD. For publishing to PyPI from GitHub Actions or another Trusted Publisher, you don't need to set any credentials. Instead, add a trusted publisher to the PyPI project.--tokenまたはUV_PUBLISH_TOKENでPyPIトークンを設定するか、--usernameまたはUV_PUBLISH_USERNAMEでユーザー名を設定し、--passwordまたはUV_PUBLISH_PASSWORDでパスワードを設定します。GitHub Actionsや他の信頼できるパブリッシャーからPyPIに公開する場合、認証情報を設定する必要はありません。代わりに、PyPIプロジェクトに信頼できるパブリッシャーを追加してください。

Note注意

PyPI does not support publishing with username and password anymore, instead you need to generate a token. Using a token is equivalent to setting --username __token__ and using the token as password.PyPIはもはやユーザー名とパスワードでの公開をサポートしていません。代わりにトークンを生成する必要があります。トークンを使用することは、--username __token__を設定し、トークンをパスワードとして使用することと同等です。

If you're using a custom index through [[tool.uv.index]], add publish-url and use uv publish --index <name>. For example:[[tool.uv.index]]を介してカスタムインデックスを使用している場合、publish-urlを追加し、uv publish --index <name>を使用します。例えば:

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
publish-url = "https://test.pypi.org/legacy/"
explicit = true

Note注意

When using uv publish --index <name>, the pyproject.toml must be present, i.e., you need to have a checkout step in a publish CI job.uv publish --index <name>を使用する場合、pyproject.tomlが存在する必要があります。つまり、公開CIジョブにチェックアウトステップを持っている必要があります。

Even though uv publish retries failed uploads, it can happen that publishing fails in the middle, with some files uploaded and some files still missing. With PyPI, you can retry the exact same command, existing identical files will be ignored. With other registries, use --check-url <index url> with the index URL (not the publishing URL) the packages belong to. When using --index, the index URL is used as check URL. uv will skip uploading files that are identical to files in the registry, and it will also handle raced parallel uploads. Note that existing files need to match exactly with those previously uploaded to the registry, this avoids accidentally publishing source distribution and wheels with different contents for the same version.uv publishは失敗したアップロードを再試行しますが、公開が途中で失敗し、一部のファイルがアップロードされ、一部のファイルがまだ欠けていることがあります。PyPIでは、同じコマンドを再試行できます。既存の同一ファイルは無視されます。他のレジストリでは、パッケージが属するインデックスURL(公開URLではない)を使用して--check-url <index url>を使用します。--indexを使用する場合、インデックスURLがチェックURLとして使用されます。uvは、レジストリ内のファイルと同一のファイルのアップロードをスキップし、競合する並列アップロードも処理します。既存のファイルは、以前にレジストリにアップロードされたファイルと正確に一致する必要があることに注意してください。これにより、同じバージョンの異なる内容のソース配布やホイールを誤って公開することを避けることができます。

Uploading attestations with your packageパッケージでのアテステーションのアップロード

Note注意

Some third-party package indexes may not support attestations, and may reject uploads that include them (rather than silently ignoring them). If you encounter issues when uploading, you can use --no-attestations or UV_PUBLISH_NO_ATTESTATIONS to disable uv's default behavior.一部のサードパーティパッケージインデックスはアテステーションをサポートしていない場合があり、アテステーションを含むアップロードを拒否することがあります(無視するのではなく)。アップロード時に問題が発生した場合は、--no-attestations または UV_PUBLISH_NO_ATTESTATIONS を使用して、uvのデフォルトの動作を無効にすることができます。

Tipヒント

uv publish does not currently generate attestations; attestations must be created separately before publishing.uv publish は現在アテステーションを生成しません。アテステーションは、公開する前に別途作成する必要があります。

uv publish supports uploading attestations to registries that support them, like PyPI.uv publish は、PyPIのようなアテステーションをサポートするレジストリにアテステーションをアップロードすることをサポートしています。

uv will automatically discover and match attestations. For example, given the following dist/ directory, uv publish will upload the attestations along with their corresponding distributions:uvはアテステーションを自動的に発見し、一致させます。例えば、次のdist/ディレクトリがある場合、uv publishは対応する配布物と共にアテステーションをアップロードします:

$ ls dist/
hello_world-1.0.0-py3-none-any.whl
hello_world-1.0.0-py3-none-any.whl.publish.attestation
hello_world-1.0.0.tar.gz
hello_world-1.0.0.tar.gz.publish.attestation

Installing your packageパッケージのインストール

Test that the package can be installed and imported with uv run:uv runを使用して、パッケージがインストールされ、インポートできることをテストします:

$ uv run --with <PACKAGE> --no-project -- python -c "import <PACKAGE>"

The --no-project flag is used to avoid installing the package from your local project directory.--no-projectフラグは、ローカルプロジェクトディレクトリからパッケージをインストールしないようにするために使用されます。

Tipヒント

If you have recently installed the package, you may need to include the --refresh-package <PACKAGE> option to avoid using a cached version of the package.最近パッケージをインストールした場合は、キャッシュされたバージョンのパッケージを使用しないようにするために、--refresh-package <PACKAGE>オプションを含める必要があるかもしれません。

Next steps次のステップ

To learn more about publishing packages, check out the PyPA guides on building and publishing.パッケージの公開について詳しく知りたい場合は、PyPAガイドをチェックしてください。

Or, read on for guides on integrating uv with other software.または、ガイドを読み進めて、uvを他のソフトウェアと統合する方法を確認してください。