Configuration
Application Kit uses Bender manifests for configuration. This guide covers how to configure your service dependencies.
Bender Manifest
Create an application.json file in your project root:
{
"name": "my_service",
"dependencies": {
"services": [],
"databases": []
}
}
Service Dependencies
Services are external HTTP APIs your application depends on.
{
"dependencies": {
"services": [
{"name": "authentication", "test_value": "http://localhost:34555"}
]
}
}
Required Services
| Service | Purpose |
|---|---|
authentication |
Token validation service |
Accessing Services
from application_kit.settings import get_service_url
# Get base URL
auth_url = get_service_url("authentication")
# Get URL with path
validate_url = get_service_url("authentication", "/validate")
Database Dependencies
Databases include Redis and PostgreSQL connections.
Redis Databases
{
"dependencies": {
"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"}}
]
}
}
| Field | Type | Description |
|---|---|---|
name |
string | Dependency name used with get_redis_instance() |
type |
string | Must be "redis" |
database |
string | Redis database number (0-15) |
extras |
object | Additional parameters (e.g., queue_prefix) |
Reserved Database IDs
To avoid conflicts between services sharing the same Redis instance, use these standardized database IDs:
| Database ID | Name | Purpose |
|---|---|---|
0 |
ratelimit |
Rate limiting counters and overrides |
1 |
authentication_cache |
Cached validated tokens |
2 |
metrics_queue |
Request counting queue |
3 |
(app-specific) | Reserved for app-specific use (e.g., Leela) |
8 |
import_queue / general_cache |
Background job queues or general caching |
10 |
general_cache |
General-purpose caching |
Always specify database
Without a database field, Redis defaults to database 0. This can cause conflicts with rate limiting data. Always explicitly set the database ID.
Accessing Redis
from application_kit.settings import (
get_redis_instance,
get_async_redis_instance,
get_redis_instance_and_extras,
)
# Sync Redis client
redis = get_redis_instance("authentication_cache")
# Async Redis client
redis = get_async_redis_instance("ratelimit")
# Get extras (e.g., queue_prefix)
redis, extras = get_redis_instance_and_extras("metrics_queue")
queue_prefix = extras.get("queue_prefix")
PostgreSQL Databases
{
"dependencies": {
"databases": [
{"name": "default", "type": "postgresql"},
{"name": "geo", "type": "postgresql", "extensions": ["postgis"]}
]
}
}
Django Database Configuration
# settings.py
from application_kit.settings import get_django_databases
DATABASES = get_django_databases()
This automatically configures Django databases from your manifest, including PostGIS support.
Direct Database URL Access
For non-Django applications (FastAPI with SQLAlchemy, InfluxDB clients, etc.), access database URLs directly:
from application_kit.settings import get_database_url
db_url = get_database_url("default")
if db_url:
# Build connection string for SQLAlchemy async
connection_string = f"postgresql+asyncpg://{db_url.user}:{db_url.password}@{db_url.host}:{db_url.port}/{db_url.name}"
The BenderDbUrl object provides:
| Property | Type | Description |
|---|---|---|
host |
str |
Database hostname |
port |
int |
Database port |
user |
str \| None |
Username |
password |
str \| None |
Password |
name |
str |
Database name |
kind |
str |
Database type (postgresql, redis, influxdb, etc.) |
get_parameters() |
dict |
Additional URL parameters |
Configuration Values
Access arbitrary configuration values from the Bender configuration backend:
from application_kit.settings import get_configuration
debug = get_configuration("DEBUG")
custom_value = get_configuration("MY_CUSTOM_CONFIG")
Environment Helpers
from application_kit.settings import (
get_version,
get_environment,
get_service_name,
get_cors_origin_whitelist,
)
# Application version (from VERSION or DD_VERSION env var)
version = get_version()
# Environment name (from ENVIRONMENT or DATADOG_ENV)
environment = get_environment()
# Service name for Datadog
service_name = get_service_name(worker_name=None)
# CORS whitelist (includes localhost in develop environment)
whitelist = get_cors_origin_whitelist()
Complete Example
{
"name": "my_api",
"dependencies": {
"services": [
{"name": "authentication", "test_value": "http://localhost:34555"}
],
"databases": [
{"name": "default", "type": "postgresql", "is_default": true},
{"name": "ratelimit", "type": "redis", "database": "0"},
{"name": "authentication_cache", "type": "redis", "database": "1"},
{"name": "metrics_queue", "type": "redis", "database": "2", "extras": {"queue_prefix": "counter"}}
]
}
}
This configuration provides:
- Authentication service for token validation
- PostgreSQL database for application data (marked as default)
- Redis db 0 for rate limiting counters
- Redis db 1 for authentication token caching
- Redis db 2 for metrics queue with custom prefix