Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Publishing to PyPI | Distribution & Publishing
Python Packaging and Distribution

bookPublishing to PyPI

Before you upload your distribution, ensure your package files are ready. You should have built distribution archives such as a source distribution (.tar.gz) and a wheel (.whl) using tools like build. These files are typically found in the dist/ directory of your project.

Security is crucial when publishing to PyPI.

  • Always use a strong, unique password for your PyPI account;
  • Enable two-factor authentication (2FA) for additional protection;
  • Never share your credentials or store them in your project repository;
  • Consider using a password manager to keep your login details secure.

To upload your package, you will use twine, which is a secure utility for publishing Python packages. Make sure you have twine installed in your environment.

# Upload your package to PyPI using twine
twine upload dist/*

After running this command, you will be prompted for your PyPI username and password. If you have enabled two-factor authentication (2FA), you will also need to provide your authentication code. Check the output for any errors, and verify your package is available on https://pypi.org/project/your-package-name/.

Note
Note

Review your package for sensitive files or credentials before uploading. Once a version is published to PyPI, it cannot be overwritten or deleted for security reasons, so double-check everything before you proceed.

question mark

What is a recommended security practice when publishing to PyPI?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 3

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

How do I generate an API token for PyPI?

Can you explain how to test my package on Test PyPI before uploading to the main index?

What should I do if I encounter an error during the upload process?

bookPublishing to PyPI

Deslize para mostrar o menu

Before you upload your distribution, ensure your package files are ready. You should have built distribution archives such as a source distribution (.tar.gz) and a wheel (.whl) using tools like build. These files are typically found in the dist/ directory of your project.

Security is crucial when publishing to PyPI.

  • Always use a strong, unique password for your PyPI account;
  • Enable two-factor authentication (2FA) for additional protection;
  • Never share your credentials or store them in your project repository;
  • Consider using a password manager to keep your login details secure.

To upload your package, you will use twine, which is a secure utility for publishing Python packages. Make sure you have twine installed in your environment.

# Upload your package to PyPI using twine
twine upload dist/*

After running this command, you will be prompted for your PyPI username and password. If you have enabled two-factor authentication (2FA), you will also need to provide your authentication code. Check the output for any errors, and verify your package is available on https://pypi.org/project/your-package-name/.

Note
Note

Review your package for sensitive files or credentials before uploading. Once a version is published to PyPI, it cannot be overwritten or deleted for security reasons, so double-check everything before you proceed.

question mark

What is a recommended security practice when publishing to PyPI?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 3
some-alt