https://github.com/billsioros/trigon
A batteries-included python web framework
https://github.com/billsioros/trigon
Last synced: 7 months ago
JSON representation
A batteries-included python web framework
- Host: GitHub
- URL: https://github.com/billsioros/trigon
- Owner: billsioros
- License: mit
- Created: 2023-09-06T10:09:37.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-29T02:46:58.000Z (over 1 year ago)
- Last Synced: 2024-05-29T16:39:10.671Z (over 1 year ago)
- Language: Python
- Homepage: https://billsioros.github.io/trigon/
- Size: 650 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: docs/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: docs/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Trigon
A batteries-included python web framework
## :rocket: Getting started
> **Attention**: The project is a work in progress and should not be used in production :construction:
Installing [`trigon`](https://pypi.org/project/trigon/) can be done as such:
```shell
pip install trigon
```The project's documentation can be found [here](https://billsioros.github.io/trigon/).
```python
from typing import Any, Dictimport uvicorn
from trigon.core.controller import Controller, http, route
from trigon.core.controller.result import Ok, Result
from trigon.middlewares.logging import LoggingMiddleware
from trigon.trigon import Trigonclass ItemService:
def get_items(self) -> list[Dict[str, Any]]:
return [
{
"id": 1,
"name": "Product 1",
"description": "This is the description for Product 1.",
"price": 19.99,
"category": "Electronics",
"stock": 50,
},
{
"id": 2,
"name": "Product 2",
"description": "A sample description for Product 2.",
"price": 29.99,
"category": "Clothing",
"stock": 100,
},
{
"id": 3,
"name": "Product 3",
"description": "Description for Product 3 goes here.",
"price": 9.99,
"category": "Books",
"stock": 25,
},
]class ItemController(Controller):
def __init__(self, service: ItemService) -> None:
self.service = service@route.get("/")
@http.status(Ok)
async def get_items(self) -> Result[list[Dict[str, Any]]]:
return Ok(self.service.get_items())if __name__ == "__main__":
app = (
Trigon()
.build_container(lambda builder: builder.singleton(ItemService))
.register_controllers(ItemController)
.configure_logging(
lambda builder: builder.override("uvicorn.error", "uvicorn.asgi", "uvicorn.access")
.add_console_handler()
.add_file_handler("logs/{time}.log"),
)
.register_middlewares(LoggingMiddleware)
.build()
)uvicorn.run(app, host="0.0.0.0", port=8000)
```> For a more elaborate example (controller discovery, database configuration, Repository-Service Pattern, etc.) check out [Example 02](./examples/example_02/).
## :sparkles: Contributing
If you would like to contribute to the project, please go through the [Contributing Guidelines](https://billsioros.github.io/trigon/latest/CONTRIBUTING/) first. In order to locally set up the project please follow the instructions below:
```shell
# Set up the GitHub repository
git clone https://github.com/billsioros/trigon.git# Create a virtual environment using poetry and install the required dependencies
poetry shell
poetry install# Install pre-commit hooks
pre-commit install --install-hooks
```Alternatively, you can support the project by [**Buying me a ☕**](https://www.buymeacoffee.com/billsioros).