Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
Python Packaging User Guide
Python Packaging User Guide
Back to top

The.pypirc file

A.pypirc file allows you to define the configuration forpackageindexes (referred to here as “repositories”), so that you don’thave to enter the URL, username, or password whenever you upload a package withtwine orflit.

The format (originally defined by thedistutils package) is:

[distutils]index-servers=first-repositorysecond-repository[first-repository]repository=<first-repository URL>username=<first-repository username>password=<first-repository password>[second-repository]repository=<second-repository URL>username=<second-repository username>password=<second-repository password>

Thedistutils section defines anindex-servers field that lists thename of all sections describing a repository.

Each section describing a repository defines three fields:

  • repository: The URL of the repository.

  • username: The registered username on the repository.

  • password: The password that will used to authenticate the username.

Warning

Be aware that this stores your password in plain text. For better security,consider an alternative likekeyring, setting environment variables, orproviding the password on the command line.

Otherwise, set the permissions on.pypirc so that only you can viewor modify it. For example, on Linux or macOS, run:

chmod600~/.pypirc

Common configurations

Note

These examples apply totwine. Other projects (e.g.flit) also use.pypirc, but with different defaults. Please refer to each project’sdocumentation for more details and usage instructions.

Twine’s default configuration mimics a.pypirc with repository sectionsfor PyPI and TestPyPI:

[distutils]index-servers=pypitestpypi[pypi]repository=https://upload.pypi.org/legacy/[testpypi]repository=https://test.pypi.org/legacy/

Twine will add additional configuration from$HOME/.pypirc, the commandline, and environment variables to this default configuration.

Using a PyPI token

To set yourAPI token for PyPI, you can create a$HOME/.pypircsimilar to:

[pypi]username=__token__password=<PyPI token>

ForTestPyPI, add a[testpypi] section, using theAPI token from your TestPyPI account.

Using another package index

To configure an additional repository, you’ll need to redefine theindex-servers field to include the repository name. Here is a completeexample of a$HOME/.pypirc for PyPI, TestPyPI, and a private repository:

[distutils]index-servers=pypitestpypiprivate-repository[pypi]username=__token__password=<PyPI token>[testpypi]username=__token__password=<TestPyPI token>[private-repository]repository=<private-repository URL>username=<private-repository username>password=<private-repository password>

Warning

Instead of using thepassword field, consider saving your API tokensand passwords securely usingkeyring (which is installed by Twine):

keyringsethttps://upload.pypi.org/legacy/__token__keyringsethttps://test.pypi.org/legacy/__token__keyringset<private-repositoryURL><private-repositoryusername>
On this page

[8]ページ先頭

©2009-2025 Movatter.jp