Metadata-Version: 2.3
Name: sftkit
Version: 0.4.2
Summary: ...
License: MIT
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Requires-Dist: fastapi>=0.115.10
Requires-Dist: typer>=0.15.2
Requires-Dist: uvicorn>=0.34.0
Requires-Dist: asyncpg>=0.30.0
Requires-Dist: pydantic[email]>=2.10.6
Maintainer: Michael Loipführer
Maintainer-email: Michael Loipführer <milo@sft.lol>
Requires-Python: >=3.11
Project-URL: Source, https://github.com/SFTTech/sftkit
Description-Content-Type: text/markdown

# SFTKit

A general purpose collection of base building blocks and utilities to make building 
python applications on the basis of postgresql (asyncpg) + fastapi a breeze.

## Getting Started
To get started simply run

```bash
pip install sftkit
```

A basic server could look like this
```python
import asyncio
from dataclasses import dataclass

from sftkit.http import Server, HTTPServerConfig
from fastapi import APIRouter


config = HTTPServerConfig(base_url="/api/v1", port=8074, host="127.0.0.1")

router = APIRouter(
    responses={404: {"description": "not found"}},
)

@router.get("/ping")
async def ping():
    return "pong"


@dataclass
class Context:
    config: HTTPServerConfig


class Api:
    def __init__(self, config: HTTPServerConfig = config):
        self.config = config
        self.server = Server(
            title="<your title>",
            config=config,
            license_name="<your license>",
            version="0.1.0"

        )
        self.server.add_router(router)

    async def run(self):
        context = Context(config=self.config)
        await self.server.run(context)

if __name__ == "__main__":
    server = Api()
    asyncio.run(server.run())
```

Copy the code to `main.py` and run the server using `python main.py`.

You can ping the server at [http://127.0.0.1:8074/api/v1/ping](http://127.0.0.1:8074/api/v1/ping) or inspect the API specification at [http://127.0.0.1:8074/api/v1/docs](http://127.0.0.1:8074/api/v1/docs).

## Usage


### Dev CLI

Configure sftkit in your `pyproject.toml`

```toml
[tool.sftkit]
db_code_dir = "<path-to-your-sql-code-folder>"
db_migrations_dir = "<path-to-your-sql-data-migrations>"
```

Create new migrations via

```bash
sftkit create-migration <name>
```
