Create a pip-installable python package in 2 minutes

Between cookiecutter, cookiecutter-pipproject, github.com and some reasonably fast typing, you can now get version 0 of a project up to pypi and pip installable in pretty much no time at all (not that you should actually do that, but you know what I mean).

The down and dirty:

pip install cookiecutter
cookiecutter https://github.com/wdm0006/cookiecutter-pipproject.git
cd projectname
git init
git add -A
git commit -m 'first commit'
git remote add origin foo://bar
git push origin master
git tag {{version}} -m 'adds the version you entered in cookiecutter as the first tag for release'
git push --tags origin master
cd ~
touch .pypirc
nano .pypirc
(add snippet from below)
cd -
python setup.py register -r pypitest
python setup.py sdist upload -r pypitest

And then you have it, the package is up on the test pypi server. Simply repeat the last two commands with pypi instead of pypitest to push to the real pip server.

As for that .pypirc file, that contains your credentials for pypi and pypi test (you need to log onto those and make accounts before you can really do this). It will look like this:

[distutils] # this tells distutils what package indexes you can push to
index-servers =
    pypi
    pypitest

[pypi]
repository: https://pypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}

[pypitest]
repository: https://testpypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}

So total of 14 commands, 2 accounts made, and a remote git repo set up somewhere (github.com is assumed by cookiecutter-pipproject), and you are up and running. Would be a difficult 2 minutes, but probably could be done.

Huge thanks to Peter Downs for his great blog on the last bit of this, which has been my personal reference in the past. If you’d like to use, contribute to, or otherwise examine the cookiecutter template referenced, you can check it out here: https://github.com/wdm0006/cookiecutter-pipproject.

Subscribe to the Newsletter

Get the latest posts and insights delivered straight to your inbox.