This is a sample package which follows the instructions for publishing a Python package to PyPI.
Project description
DEMO-PACKAGE-PYTHON
This sample package follows the instructions for publishing a Python package in PyPI.
This repository can be used as a template for building packages.
See section Reusing as Template for more info on how.
Outline
This README.md file is organized as follows:
- Outline
- Full Instructions
- Summarized/Compact Instructions
- Code Structure
- Demo Package Installation Instructions
- Reusing as Template
- Adding Additional Files
Full Instructions
Full instructions for publishing a Python package using PyPI can be found here: https://packaging.python.org/en/latest/tutorials/packaging-projects/
I made a tinyurl.com short-link for the
tutorial link above:
https://tinyurl.com/how-to-package-python
If you want, you can include the links above in your bookmarks.
Summarized/Compact Instructions
In summary, the instructions can be divided into the outline below if you don't feel like clicking the tutorial link again and again.
Full instructions can be found in the tutorials above in case the summary doesn't still help in recalling the procedures.
- Creating a package
- Create package files (see code structure below for an example)
- Create
test/directory - Create
pyproject.tomlwith the necessary[build-system],[project], and[project.urls]options - Configure metadata of project. Common metadata are shown below. For a more thorough example, see
pyproject.toml- name
- version
- authors (must be in array format)
- description
- readme
- license
- requires-python
- classifiers
- Create
README.mdfile - Create
LICENSEfile
- Generating distribution archives
- Step 1: Install
buildpackage
python3 -m pip install --upgrade build`- Step 2: Run
python3 -m buildon the first build and successive build updates for different versions.- Generates a
dist/folder for the built package - Puts a
.whland.tar.gzfile in the dist folder for the current version.
- Generates a
- Step 1: Install
- Uploading the distribution archives
- Install
twine, a tool for uploading packages to different package indices.python3 -m pip install --upgrade twine - Upload archives under
distpython3 -m twine upload --repository testpypi dist/*
- Install
Code Structure
demo-package-python
dist/ # distribution files
env/ # virtual environment for the package
scripts/ # scripts
build_pyproject_toml.py # build pyproject_toml.py
src/ # source files for the package
tests/ # tests for the package
main.py
utils/
build.sh # shell script for building package
publish.sh # shell script for publishing package
setup.sh # shell script for setting up package
LICENSE # MIT License
pyproject.dev.toml # project configuration
pyproject.toml # built project configuration
requirements.txt # requirements list generated by pip freeze
Demo Package Installation Instructions
The demo package has a simple API of 3 functions.
.say_hello_world().say_hi(name).random_rainbow_color()- uses thefakerpackage
To use this package:
pip install demo_package_python
Then:
import demo_package_python as demo_package
print(".sayHello() => " + demo_package.say_hello_world())
print(".sayHi('John') => " + demo_package.say_hi('John'))
print(".randomRainbowColor() => " + demo_package.random_rainbow_color())
It should return the following:
.say_hello() => Hello, World!
.say_hi('John') => Hi, John!
.random_rainbow_color() => blue
Reusing as Template
If you intend to reuse this package as a template for future package projects, use the following command:
-
git clone https://gitlab.com/demo-package/demo-package-python.git -
Edit
pyproject.tomlto match your project description. -
Remove contents of
src/demo_package_python -
Rename
src/demo_package_pythontosrc/[your_project_name] -
Make sure that your have
virtualenvinstalled and then run the followingvirtualenv envor
python3 -m venv env -
Activate virtual environment
source env/bin/activate -
Run from the command line:
bash utils/setup.sh -
Use the following commands to simplify routines:
bash utils/build.sh- to build projectbash utils/publish.sh- to upload the project
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file demo_package_python-0.0.15.tar.gz.
File metadata
- Download URL: demo_package_python-0.0.15.tar.gz
- Upload date:
- Size: 11.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82e794623333113b65f89a6d3900d5e629f3b370828dd69554ea160db1b72a5a
|
|
| MD5 |
058317f974ab5906a772d3b494b17fde
|
|
| BLAKE2b-256 |
743b7930e55d871f9138cdfde73196cf2e2c1d9690c71132d2f45a6263c68a42
|
File details
Details for the file demo_package_python-0.0.15-py3-none-any.whl.
File metadata
- Download URL: demo_package_python-0.0.15-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd33704e08cbed9a0ca1e43c7ed8f56061439a2b8c41bab5b79cfcc1d0a2171a
|
|
| MD5 |
5cbafd19faa654ab0bb91592a6ee6e5e
|
|
| BLAKE2b-256 |
60c570fcfdb296c30e757a126e829113cc14a01c4c2b6e92fc4b4a73fe8335e6
|