# How to structure your python code

1 minute read

In this post I want to show you how you can set up and structure your python code if you don’t know where to start. Just copy our setup!

This is actually how we lay out most of our python projects here at Snappet (We’re hiring!).

I made a small repository that is fully functional (you can build the docker, run the code, etc.) that shows how we structure our code.

View the repository on Github here.

What I really like about this setup:

• Conda + Poetry for environment and package management For our environment and package management we use a combination of Conda and Poetry. We have a separate virtual environment for all our projects each with their own pyproject.toml.
• Clear separation of the interface/entrypoint and the code This setup clearly separates the interface of the code (in the entrypoints/ folder) from the source code (in the src/ folder). If you don’t know the project at all you should, in theory, be able to run everything by just fiddling with the entrypoint knobs.
• Containerisation using docker. This setup (thanks to poetry) also allows us to install the source folder as a package which makes it easy to dockerize, yet, at the same time we can run it locally using the entrypoint too. The docker just installs the package and calls the entrypoint.

Tags:

Categories:

Updated: