Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Publishing to PyPI | Distribution & Publishing
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
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

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookPublishing to PyPI

Swipe to show 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

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 3
some-alt