My PyPI Package Project
A sample project to create a Python package and publish it to PyPI. https://pypi.org/project/hanbin-hello/
Credit to https://www.youtube.com/watch?v=Kz6IlDCyOUY
Setting Up
To set up your Python environment for publishing your own package, you will need to install setuptools, wheel, and twine.
You can install these tools using pip:
pip install -r requirements.txt
This provides a cleaner and more straightforward way for users to interact with your package, as they can simply use from hanbin_hello import hello instead of navigating through deeper module structures.
from hanbin_hello import hello
In this example, replace 'your-package-name' with the actual name of your package. The version field should be set to the desired version number of your package.
Additionally, you can specify any dependencies your package requires in the install_requires list. For example, if your package requires NumPy version 1.11.1 or higher, you can add 'numpy>=1.11.1' to the list.
It is also recommended to create a README.md file where you can describe your package. This file should be written in Markdown format and can provide information about the purpose of your package, how to install it, and any other relevant details.
Build Your Package
To build your package, you will need to use the setuptools and wheel libraries. These libraries allow you to generate distribution archives that can be installed using pip. You have already installed these from the first step of this tutorial.
You can build your package by running the following command:
python setup.py sdist bdist_wheel
This command will generate two distribution archives: a source distribution (sdist) and a wheel distribution (bdist_wheel). These archives contain all the necessary files for installing your package.
Local Testing
Before publishing your Python package, it's crucial to test it locally to ensure it functions correctly. Follow these steps to install and test your package using pip:
- Open your terminal or command prompt.
- Navigate to the directory where your package is located.
- Run the following command to install your package locally.
pip install dist/xxx.whl
Replace the package name with the actual name and version of your package. Once the installation is complete, you can now test your package by importing it in a Python script or interactive session and using its functionality.
# In a different file...
from hanbin_hello import hello
hello()
By testing your package locally, you can identify and fix any issues before publishing it to PyPI.
Publish to PyPI
To publish your Python package to PyPI, you can use the twine tool.
twine upload dist/*
You will be prompted for your PyPI credentials. Once uploaded, anyone can install your package using.
pip install hanbin_hello
Useful Links
Metadata
Release files for hanbin-hello 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hanbin_hello-0.2.0.tar.gz | 2.6 kB | Without provenance | Details for hanbin_hello-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hanbin_hello-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for hanbin_hello-0.2.0-py3-none-any.whl |
Total release size: 5.7 kB
Release files / hanbin_hello-0.2.0.tar.gz
| Download URL | hanbin_hello-0.2.0.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89798a6ce57f6e94f995e41cd668ff7df464bdf8bc7a78c684f40af8d237059e
|
|
BLAKE2b-256 checksum How to use checksums |
9472f82169d82065aa60ad2d515932ed2cfa4bc6751afabf0ed6c76d8e03bf54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / hanbin_hello-0.2.0-py3-none-any.whl
| Download URL | hanbin_hello-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
535711dcee8c2695cfef93b411eb8608ebf2bd257abe1478983b4589d450bb7c
|
|
BLAKE2b-256 checksum How to use checksums |
3145c3ad8bb7c2afdd77db40358671538cce75fd7d8eede0444289d6584ce1e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Security for hanbin-hello 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.