Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/cgund98/python-template
- Owner: cgund98
- Created: 2024-07-31T23:07:37.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T04:24:26.000Z (6 months ago)
- Last Synced: 2024-08-01T07:17:53.423Z (6 months ago)
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```