Python Coding Guidelines
Our recommendations for creating and maintaining reliable scientific software in Python.
Good default choices
Here are our suggested default choices for build systems and third party libraries, which are all widely used and well supported:
- Version control: GitHub
- de facto standard for open source software
- start from our Python template repository
- private repos also available
- Testing framework:
- Continuous Integration: GitHub Actions
- well integrated with Github
- Documentation: Sphinx
- The default for Python documenation
- Python version: 3.7 (or higher)
For each choice there are of course many alternatives, each with their pros and cons, but these represent a sensible default choice for the vast majority of Python projects.
Our Python Project Template is a simple way to
start a new Python project with all of the above already set up - just click on the green
Use this template button.
Good tools make it easier to develop good code. Unlike the previous section, where a single choice must be made for the project, each person contributing to a project can use whichever tools they prefer. Some recommendations:
- Code formatting
- Keep your code clean using linters such as flake8
There is a vast abundance of available modules in Python. For common problems in scientific computing, use
- use case: array and matrix operations, mathematical functions
- use case: enhanced linear algebra, additional mathematical functions compared to numpy
- use case: symbolic math (e.g. differentiation)
- use case: statistical data analysis and data transformation
- use case: statistical data visualization
- use case: machine learning objectives, build and run your own ML models
- This list is by no means complete. Check e.g. PyPi and SciKits for more options.