Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cgund98/python-template

Template for miscellaneous python projects. Can be used as a base for APIs, CLIs, or more.
https://github.com/cgund98/python-template

Last synced: 4 days ago
JSON representation

Template for miscellaneous python projects. Can be used as a base for APIs, CLIs, or more.

Awesome Lists containing this project

README

        

# Python Project

Template for miscellaneous projects. Just for fun, we created a submodule for interacting with the public [Cat Facts API](https://catfact.ninja/#/Breeds/getBreeds). This should help to demonstrate how this template works in practice.g

## Project Structure
While there is no single optimal project structure, I typically prefer a domain-driven layout.

```
├── python_template # name of your module
│ ├──
│ │ ├── controller.py # business logic
│ │ ├── schemas.py # pydantic models
│ │ ├── models.py # db models
│ │ ├── config.py # local configs
│ │ ├── constants.py
│ │ ├── exceptions.py # domain-specific exceptions
│ │ ├── service.py # calls to external APIs or databases
│ │ └── utils.py
│ ├── config.py # global configs
│ ├── exceptions.py # global exceptions
│ └── __main__.py # app entrypoint
├── tests/ # Unit tests
├── .env
├── .gitignore
└── pyproject.toml # Poetry and linter configuration
```

## Running the Application

### Prerequisites

- [poetry](https://python-poetry.org/docs/#installation) - all-in one tool to handle dependencies and virtual environments
- _[pre-commit](https://pre-commit.com) (Optional)_ - useful for automating various formatting and linting processed as git hooks.

### Run the program

Poetry will manage the environment and install dependencies for us. Once installed, all you have to do is run the program with `poetry run`.

```bash
# Install dependencies
poetry install

# Run program.
poetry run python -m python_template
```

### Unit Tests

```bash
poetry run pytest
```

### Linting and Formatting

We can easily run our static code analysis tools with `pre-commit`.

```bash
# Install hooks
pre-commit install

# Optionally run the hooks on the entire codebase
pre-commit run --all-files
```