Skip to content

A repository containing our API Spec, and all the code generation logic used to power our API Docs, Postman, and SDKs.

License

Notifications You must be signed in to change notification settings

gravity-technologies/api-spec

Repository files navigation

uv logo pre-commit logo ruff logo bandit logo pytest logo

Docker logo GitHub Actions logo

Python boilerplate

CodeQL GitHub CI GitHub license


Table of Contents


Prerequisites


Installation

  1. Clone the git repository

    git clone https://github.com/smarlhens/python-boilerplate.git
  2. Go into the project directory

    cd python-boilerplate/
  3. Checkout working branch

    git checkout <branch>
  4. Enable pre-commit hooks

    pre-commit install

What's in the box ?

uv

uv is an extremely fast Python package and project manager, written in Rust.

pyproject.toml file (pyproject.toml): orchestrate your project and its dependencies uv.lock file (uv.lock): ensure that the package versions are consistent for everyone working on your project

For more configuration options and details, see the configuration docs.

pre-commit

pre-commit is a framework for managing and maintaining multi-language pre-commit hooks.

.pre-commit-config.yaml file (.pre-commit-config.yaml): describes what repositories and hooks are installed

For more configuration options and details, see the configuration docs.

ruff

ruff is an extremely fast Python linter, written in Rust.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

mypy

mypy is an optional static type checker for Python that aims to combine the benefits of dynamic (or "duck") typing and static typing.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

bandit

bandit is a tool designed to find common security issues in Python code.

Rules are defined in the pyproject.toml.

For more configuration options and details, see the configuration docs.

docformatter

docformatter is a tool designed to format docstrings to follow PEP 257.

Options are defined in the .pre-commit-config.yaml.


Testing

We are using pytest & pytest-cov to write tests.

To run tests:

uv run pytest tests
Output
collected 1 item

tests/test_myapplication.py::test_hello_world PASSED

To run tests with coverage:

uv run pytest tests --cov=src
Output
collected 1 item

tests/test_myapplication.py::test_hello_world PASSED

---------- coverage: platform linux, python 3.10.4-final-0 -----------
Name                            Stmts   Miss  Cover
---------------------------------------------------
src/myapplication/__init__.py       1      0   100%
src/myapplication/main.py           6      2    67%
---------------------------------------------------
TOTAL                               7      2    71%

Docker

Build

To build the docker production image using Dockerfile:

docker build . -t my-python-application:latest

To build the docker development image using Dockerfile:

docker build . --target development -t my-python-application:dev

Run

To run the python app example inside Docker:

docker run -it --rm my-python-application:latest # or :dev for development
Output
Hello World

Execute command inside container

docker run -it --rm my-python-application:latest bash

Makefile

We are using Makefile to manage the project.

To see the list of commands:

make
➜  api-spec git:(main) ✗ make
help                           Show this help
run                            Run the project
test                           Run the tests
lint                           Run the linter
format                         Run the formatter
typecheck                      Run the type checker
security                       Run the security checker
clean                          Clean the project
install                        Install the project

About

A repository containing our API Spec, and all the code generation logic used to power our API Docs, Postman, and SDKs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages