Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dzooli/blacksheep-template
A simple API backend template using the Blacksheep framework.
https://github.com/dzooli/blacksheep-template
api backend backend-api blacksheep python3 rest rest-api restful restful-api
Last synced: 2 days ago
JSON representation
A simple API backend template using the Blacksheep framework.
- Host: GitHub
- URL: https://github.com/dzooli/blacksheep-template
- Owner: dzooli
- License: mit
- Created: 2024-04-28T16:40:37.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-09-30T23:04:22.000Z (4 months ago)
- Last Synced: 2024-11-21T05:16:26.123Z (2 months ago)
- Topics: api, backend, backend-api, blacksheep, python3, rest, rest-api, restful, restful-api
- Language: CSS
- Homepage:
- Size: 79.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Blacksheep API template
## Description
A template for Blacksheep-based API with the following features:
- Flexible package manager: [hatch](https://hatch.pypa.io/latest/), poetry or pip
- Separated requirements.txt files for the app, for development and for documentation.
- Using environment variables for separated development and production execution
- Unit-testing setup with working autodiscovery in VSCode
- Swagger UI on /docs endpoint
- Path-based API versioning
- Class-based views and endpoints
- Response types based on ```dataclasses.dataclass```
- Fast JSON serializer using [orjson](https://github.com/ijl/orjson)
- Async template rendering
- Built-in anti-forgery (commented out in server.py)
- MkDocs for documentation
- Automated source code docstring extraction
- API documentation from openapi.json - needs to be saved before
- Clear structure## Usage
Even if using this template is possible with regular pip+virtualenv tool combination I kindly recommend to use ```hatch``` as a more powerful package and task management tool.
Once ```hatch``` is installed on your Linux (physical, WSL, Docker or VM) environment using this template is very simple. The main tasks are included into ```pyproject.toml``` so you only need the required command to perform these tasks:
- Start dev server
```shell
hatch run serve
```
- Run tests
```shell
hatch run test:test
```
- Run tests with coverage measurement
```shell
hatch run test:test-cov
```
- Generate coverage report (lcov and xml, usable with coverage-gutters VSCode extension)
```shell
hatch run test:cov
```
- Doc development with live reload
```shell
hatch run doc:serve
```
- Build the docs into ./build/docs
```shell
hatch run doc:build
```
- Format check (ruff)
```shell
hatch fmt --check
```
- Formatting
```shell
hatch fmt
```
- Build wheels and sdist packages
```shell
hatch build
```## Debug setup
With VSCode use the following ```launch.json```:
```json5
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Server",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/src/app/server.py",
"console": "integratedTerminal",
//"args": "${command:pickArgs}",
"env": {
"APP_ENV": "dev",
"PYTHONPATH": "${workspaceFolder}/src"
}
}
]
}
```## Contribution
Create your fork and submit pull-requests.