If you are like me, every once in a while you write a useful python utility and want to share it with your colleagues. The best way to do this is to make a package: it easy to install and saves from copy-pasting.
Find out top Awesome python curated list. Python Book, Community, Course, Tutorial, YouTube, and more. Your go-to Python Toolbox. Our goal is to help you find the software and libraries you need. Made by developers for developers. The collection of libraries and resources is based on the Awesome Python List and direct contributions here. To add a new package, please, check the contribute section. Awesome Python Binding Generators for C C/C to Python Boost.Python. AutoWIG - Automatic wrapper and interface generator ; chimera - Utility for generating Boost.Python and pybind11 bindings from C/C code pybind11.
Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. The Awesome Python feed Scout APM - Leading-edge performance monitoring starting at $39/month Scout APM uses tracing logic that ties bottlenecks to source code so you know the exact line of code causing performance issues and can get back to building a great product faster.
If you are like me, you might be thinking that creating packages is a real headache. Well, that’s not the case anymore. And I am going to prove it with this step-by-step guide. Just three main steps (and a bunch of optional ones) accompanied by few GitHub links. See for yourself:
We will create
podsearch - a utility that searches for podcasts in iTunes. Let’s create a directory and a virtual environment:
Define a minimal package structure:
2. Test package
Creating a package in Python used to be a troublesome task. Fortunately, nowadays there is a great little flit utility which simplifies everything. Let’s install it:
And create package description:
Flit has created
pyproject.toml - the project metadata file. It already has everything you need to publish the package to the public repository - PyPI.
Sign up for TestPyPi (test repository) and PyPI (the main one). They are completely independent, so you will need two accounts.
Awesome Python Applications
Setup access to repositories in the
And publish the package to the test repository:
Awesome Python Turtle Codes Pdf
Done! The package is available on TestPyPi.
3. Public package
Let’s improve the code so that it actually searches for podcasts:
And publish to the main repository - PyPI. Perform this step only after your package has working code that does something useful. Do not publish non-working packages and stubs.
Done! Time to share it with colleagues.
To make the package a pleasure to use, I recommend that you follow a few more steps.
A. Readme and changelog
No one likes to write documentation. But without docs, it is unlikely that people will want to install your package, so let’s add
Add readme to the
pyproject.toml, so that PyPI shows it on the package page:
Also specify the minimal supported Python version:
Update the version in
__init__.py and publish the package via
B. Linters and tests
Let’s take care of formatting (
black), test coverage (
coverage), code quality (
mccabe), and static analysis (
mypy). We will run everything through
tox configuration in
And run all the checks:
Lovely! The linters are happy, the tests passed, the coverage is 100%.
Awesome C Github
C. Cloud build
Every solid open-source project runs cloud tests after each commit, so we will too. A nice side effect is having beautiful badges in the readme ツ
Let’s build the project with GitHub Actions, check test coverage with Codecov and code quality with Code Climate.
You will have to sign up for Codecov and Code Climate (both support GitHub login) and enable package repository in the settings.
After that, add the GitHub Actions build config to
GitHub runs tests via
tox - just as we did.
tox-gh-actions package and
USING_COVERAGE settings ensure that
tox uses the same Python version as GitHub Actions themself, as required by
strategy.matrix (I learned this clever trick from Hynek Schlawak).
The last step sends test coverage to Codecov. Code Climate does not need a separate step - it spots repository changes automatically.
Now commit, push, and enjoy the result in a minute. And let everyone enjoy as well - add badges to
Aren’t they cute?
D. Task automation
tox is fine, but not very handy for development. It’s faster to run individual commands like
coverage etc. But they are quite verbose, so we’ll automate the boring stuff.
Let’s create short aliases for frequent actions with Makefile:
Here are our tasks:
To make the code more DRY, replace raw
build.yml steps with
E. Cloud publish
GitHub is quite capable of running
flit publish for us. Let’s create a separate workflow:
PYPI_PASSWORD are set in repository settings (Settings > Secrets > New repository secret). Use your PyPi username and password, or even better - an API token.
Now GitHub will automatically publish the package as soon as you create a new release. Sweet!
⌘ ⌘ ⌘
Your perfect package is ready! It has everything one could dream of: clean code, clear documentation, tests, and cloud builds. Time to tell your colleagues and friends.
These settings will make your package awesome:
Cool Python Apis
Thanks for reading! Follow @ohmypy on Twitter to keep up with new posts 🚀