Skip to main content

A batteries-included python web framework

Project description

Trigon

A batteries-included python web framework

CD pre-commit.ci status Open in GitHub Codespaces Renovate - Enabled Dependency Review Cookiecutter Template Buy me a coffee

:rocket: Getting started

Attention: The project is a work in progress and should not be used in production :construction:

Installing trigon can be done as such:

pip install trigon

The project's documentation can be found here.

from typing import Any, Dict

import uvicorn
from trigon.core.controller import Controller, http, route
from trigon.core.controller.result import Ok, Result
from trigon.trigon import trigon


class 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")
            .register_middleware()
            .add_console_handler()
            .add_file_handler("logs/{time}.log"),
        )
        .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.

:sparkles: Contributing

If you would like to contribute to the project, please go through the Contributing Guidelines first. In order to locally set up the project please follow the instructions below:

# 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 ☕.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trigon-0.2.0.tar.gz (16.2 kB view hashes)

Uploaded Source

Built Distribution

trigon-0.2.0-py3-none-any.whl (20.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page