< ^ >

Pypi - creating a python package

I just had my first rodeo with Pypi - time to put down some hopefully helpful notes, most likely for myself in 6 months. First things first, make an account (or for my future self: remember your passwords) at pypi and testpypi.

To create a package one needs to include a setup.py file into the root directory of the project. The most basic structure of the file would be

import pathlib
from setuptools import setup

# This call to setup() does all the work
setup(
    name="pkgname",
    version="1.0.0",
    description="...",
    packages=["pkgname"],
    },
)

To point to the directory of your pkg add a line like

    package_dir={"pkgname": "dir"},

It is possible to include source files relative to this directory by adding a line like

    package_data={"pkgname": ["*"]},

Now it should be possible to run the file

python setup.py sdist 

here sdist is to build a source distribution, other options check

python3 setup.py --help-commands

The source pkg should land in the ./dist folder. Time to check out the results

python3 -m venv env
source env/bin/activate
pip install dist/* 

To upload it to the test server use

twine upload --repository testpypi dist/*

This site was very helpful.