Skip to main content

No project description provided

Project description

Python Library Creation

This is a simple example

Required Libraries

pip install setuptools wheel twine

Project Structure

library_example/
	library_example/
	  __init__.py
	  main.py
	setup.py
	Readme.md

Build library for distribution

  • sdist: distribute scripts
  • bdist_wheel: distribute binary
python setup.py sdist bdist_wheel

From the wheel (.whl) file created in the last step we can install the library locally. This will make it available for testing.

Local Install

pip install dist/library_example-0.1-py3-none-any.whl

Create a CLI Command

Extend the setup.py by adding the following entry_point section:

setup(
  ...
  entry_points={
      "console_scripts": [
        "library_example = library_example:hello",
      ],
  }
)

Pushing to PyPi

twine upload dist/*

As this command will ask for authentication one can instead of manually entering credentials use environment variables:

This will work with api tokens or username/password


Actually I had a problem getting the username/password to work propertly and switched to using an API token

export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-xxxx

Pushing to a Test Repository

Rather then sharing with the world you can push to a test repository:

# Upload to test repository
twine upload --repository testpypi dist/*

# Install from the test repository.
pip install \
  --index-url https://test.pypi.org/simple/ \
  --no-deps library_example-YOUR-USERNAME-HERE
  
### Register a new test user

[](https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives)





Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

library_example-0.4.0.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

library_example-0.4.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file library_example-0.4.0.tar.gz.

File metadata

  • Download URL: library_example-0.4.0.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for library_example-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5d32e3369c331a26a07e4954ce62f1d90be30be2c2d796ed1c21d5a817a02b22
MD5 6eaa95c669f750f9187c86a550f74284
BLAKE2b-256 75bbbe52f80174073b8a5a190f8cd6d7fc3d4556c7efda335e1232632df37d08

See more details on using hashes here.

File details

Details for the file library_example-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for library_example-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8d24583c9cff355d460a695eac5f43804f77f1903a2ee35463be2997d84e171
MD5 9c00e8a047b553c33c8a8108995ce951
BLAKE2b-256 db5e42aad1831b46e15250ec025762181f76507459a70e866db44110a23b86ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page