Python Coding Conventions

Generally speaking, follow Pythonic coding styles and guidelines.

This document is designed to point you in the right direction and propose a few approaches to coding to maintain consistency.

Project Conventions

Projects must be designed and organized in a specific way to ensure they are both docker compatible and they will continue to function going forward. PEP-518 lays out a new project format to describe project dependencies. In addition PEP-517 describes a very-likely to pass way to handle and build project dependencies.

As part of adapting to the changing landscape we are changing from the pipenv tool to poetry. Pipenv no longer fits in the broader vision of how Python dependencies are managed and never provided much of a deployment vision, either.

Poetry, on the other hand, maintains a somewhat opinioned vision of how to build and deploy Python applications and libraries both that is consistent with the future of Python (already integrates the pyproject.toml) as well as intends to provide standardized hooks for build and deployment.

.
├── app
│   ├── subpackage
│   │   ├── __init__.py
│   │   └── somefile.py
│   ├── main.py
│   └── __init__.py
└── pyproject.toml

Note that the pyproject sits one level above the actual code. This is very similar to, like, C/C++ projects or Go projects where you’d typically have your project file sitting above the source files. Ideally this should be a more familiar and considerably easier to build format.

Naming and Style Conventions

Classes vs. Modules vs. Packages

Dependency Injection

Environment and Setup

Cross Platform

Type Annotations

Docstrings