Steps for new Python library or package

Here are the steps.

Create repo on github with license, gitignore and readme stubs.

Clone the repo in the work area.

Lets say, my new library is called new-library

new-library is the repo name.

Inside the cloned repo, create virtual env by running:
pipenv install --python 3.8

Above step creates a virtualenv using python 3.8 (already installed on my system)

now install all the required packages. The basic ones I always install are:
pytest, pytest-cov, typing, codecov, mypy and flake8

pipenv shell

pipenv install pytest pytest-cov typing codecov mypy flake8


# IDE dirs

to .gitignore

create a directory called new-library (inside the directory new-library .. this is also the repo). Inside this, create a file called new-library is now a Python package. I tend to have my blank.

lets create a file called inside this directory so that we have something to work with.

Now lets create a tests directory right under the repo directory (called new-library). This tests directory is at the same level as .gitignore and files.
Inside this directory, create Then create a file called

Now create a .coveragerc file to configure code coverage. This file is also at the root level (same level as .gitignore)

Now create a setup.cfg file where you can put configuration details. Again at the root.

Now create a file. Again at root level.

Now, lastly create .travis.yml file. Again at root level.

Don’t forget to register and enable the repo in Travis CI dashboard before checking in the project. Now, after you check in all changes to github, you will see that build gets triggered in travis.

locally, you can run the tests with coverage using:
pytest --cov=new-library tests/

You can check the compile with type safety:
mypy new-library --ignore-missing-imports

You can check linting:
flake8 new-library

Steps for PyPi package

first install check-manifest for creating
pipenv install --dev check-manifest

create a source distribution for PyPi
python sdist

now check the distribution created for all the files:
tar tzf dist/read-only-attributes-1.0.tar.gz

It will be missing Pipfile, Pipfile.lock and LICENSE files. You need to create a to include these files.
check-manifest --create

Now re-create source distribution to include the files listed in the and then check to see that the are in the dist
python sdist
tar tzf dist/read-only-attributes-1.0.tar.gz

Now we are ready to publish it.
So lets build the .whl distribution file for PyPi
python bdist_wheel sdist

check the dist folder to ensure that .gz and .whl files were created
ls dist/

Now we are ready to upload to PyPi.
Since we need twine to upload to PyPi, install it first
pipenv install --dev twine

now upload it:
twine upload dist/*

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *