Skip to content

Getting Started

This guide walks you through setting up Application Kit for your Woosmap service.

Installation

Install Application Kit with the extras for your framework:

pip install application-kit[fastapi]
pip install application-kit[django]
pip install application-kit[ninja]

Configuration

Application Kit uses Bender manifests for configuration. Create an application.json file in your project root:

{
  "dependencies": {
    "services": [
      {"name": "authentication", "test_value": "http://localhost:34555"}
    ],
    "databases": [
      {"name": "ratelimit", "type": "redis", "database": "0"},
      {"name": "authentication_cache", "type": "redis", "database": "1"},
      {"name": "metrics_queue", "type": "redis", "database": "2", "extras": {"queue_prefix": "counter"}}
    ]
  }
}

Required Dependencies

Dependency Purpose
authentication URL to the authentication service
authentication_cache Redis for caching validated tokens

Optional Dependencies

Dependency Purpose
metrics_queue Redis for metrics collection
ratelimit Redis for rate limiting counters

Framework Setup

Use the provided app factory and security dependencies:

"""FastAPI quick start example."""

from fastapi import Depends

from application_kit.fastapi.fastapi import get_fastapi_app
from application_kit.fastapi.security import AuthenticateKey

app = get_fastapi_app("api")


@app.get("/endpoint", dependencies=[Depends(AuthenticateKey())])
async def my_endpoint() -> dict[str, str]:
    return {"status": "ok"}

Add authentication to your views using decorators:

"""Django quick start example."""

from django.http import HttpRequest, JsonResponse

from application_kit.django.decorators import authenticate_key, count_request


@authenticate_key()
@count_request("my_endpoint", "MY_SERVICE")
def my_view(request: HttpRequest) -> JsonResponse:
    return JsonResponse({"status": "ok"})

Not recommended for new projects

Django Ninja support is maintained for existing projects. For new projects, use FastAPI instead.

Use the Shinobi module for Django Ninja integration:

"""Django Ninja quick start example."""

from django.http import HttpRequest

from application_kit.django.decorators import authenticate_key
from application_kit.shinobi.api import WoosmapApi
from application_kit.shinobi.authentication import PublicKeyAuth
from application_kit.shinobi.decorators import chain, terminate

api = WoosmapApi(description="My API")


@api.get("/endpoint", auth=[PublicKeyAuth()])
@chain(authenticate_key())
@terminate()
def my_endpoint(request: HttpRequest) -> dict[str, str]:
    return {"status": "ok"}

Next Steps