This is a simple example package created from the packaging-project tutorial at https://packaging.python.org/tutorials/packaging-projects/.
Comments and most of the README content are taken from this tutorial.
Note:
You can use
Github-flavored Markdown
to write your content.
See https://choosealicense.com/ for picking a license. In the LICENSE file, paste the text of the license to be used. If the License field is left blank, this means no one will be able to use the package.
Every package uploaded to the Python Package index should include a license. The license tells users installing the package the terms under which they can use the package.
Distribution packages are archives uploaded to the Package Index. They can be installed with pip. To generate a distribution package:
- Ensure the latest versions of
setupttoolsandwheelare installed with this command:
python3 -m pip install --user --upgrade setuptools wheel - Next, run the following command from the same directory where setup.py is located:
python3 setup.py sdist bdist_wheel - Once complete, two files should be generated in the
distdirectory:
- Built Distribution, with a .wh1 extension and
- Source Archive, with a .tar.gz extension
You should always upload a source archive and provide built archives to identify platforms that are compatible with your project.
Follow these steps to upload the package to the Python Package Index. (Note these instructions are for using the Test PyPI).
- First, register an account on Test PyPI at https://test.pypi.org/account/register/ (used for testing and experimentation).
- Create a PyPI API token at https://test.pypi.org/manage/account/#api-tokens in order to securely upload the project. Make sure to copy and save the token before closing this page.
- Install
Twinein order to upload the distribution packages with the following code:
python3 -m pip install --user --upgrade twine - Next, run the following command to upload all of the archives under
dist:
python3 -m twine upload --repository testpypi dist/* - When prompted for a username and password, use
__token__for the username. For the password, use the token value you copied earlier, prefixed withpypi
Once uploaded, the package should be viewable on TestPyPI, e.g., https://test.pypi.org/project/example-pkg-YOUR-USERNAME-HERE.
Use pip to install the package and verify that it works:
- First, create a new virtualenv and install your package from TestPyPI:
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps example-pkg-YOUR-USERNAME-HERE - Make sure to specify your username in the package name.
- Next, ensure the package was installed correctly by importing it. Run the Python interpreter in the virtualevn with the
pythoncommand. - Finally, from the interpreter shell, import the package:
>>> import example_pkg