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
tests/
directory - Create
pyproject.toml
with 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.md
file - Create
LICENSE
file
- Generating distribution archives
- Step 1: Install
build
packagepython3 -m pip install --upgrade build`
- Step 2: Run
python3 -m build
on the first build and successive build updates for different versions.- Generates a
dist/
folder for the built package - Puts a
.whl
and.tar.gz
file 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
dist
python3 -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 thefaker
package
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 commands:
-
Clone the project:
git clone https://github.com/lvjhn/demo-package-python [your_project]
-
Go to your project directory:
cd [your_project]
-
Edit
pyproject.dev.toml
to match your project description:Make sure to edit the right file, you might accidentally edit
pyproject.toml
instead.The file
pyproject.toml
is automatically built frompyproject.dev.toml
by adding the dependencies list inrequirements.txt
before building. -
Remove contents of
src/demo_package_python
:rm -rf src/demo_package_python/*
-
Create
__init__.py
insrc/demo_package_python
:touch src/demo_package_python/__init__.py
-
Rename
src/demo_package_python
tosrc/[your_project_name]
:mv src/demo_package_python src/[your_package_name]
-
Make sure that your have
virtualenv
installed and then run the following:virtualenv env
or
python3 -m venv env
-
Activate virtual environment:
source env/bin/activate
Make sure that the virtual environment is activated before running the succeeding commands.
-
Run from the command line:
bash utils/setup.sh
This command should install the packages on the
env/
folder and not on the default location. -
Use the following commands to simplify building and publishing routines:
Make sure to run the following commands in the virtual environment mode by running
source env/bin/activate
if you haven't yet.- To Build Project
bash utils/build.sh
- To Publish Project
bash utils/publish.sh
- To Build 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
File details
Details for the file custom_bench_fsr-0.0.22.tar.gz
.
File metadata
- Download URL: custom_bench_fsr-0.0.22.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1b83794cf81555be129cafefeacedc17a2d23655a87b266665dd26919fa9694 |
|
MD5 | dd8bef3d968e9b38f37cca8b255abbf8 |
|
BLAKE2b-256 | 95922cd6dccfb7ad93330fd2e988e44dbccae9b87990e743218c4a14a6b3bb20 |
File details
Details for the file custom_bench_fsr-0.0.22-py3-none-any.whl
.
File metadata
- Download URL: custom_bench_fsr-0.0.22-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95b3d86e74a23c128333a71f91a4afdea96e05320304f833a2c4428d841f9911 |
|
MD5 | 6310d65e853f310b29cd642d7d94b35a |
|
BLAKE2b-256 | 101d1beef7bcc9a901f8278cf3efc273fd8fcd165a0582d9bab5cc29c4471f3a |