Configuration Reference
Complete reference for all Singularity configuration options — Settings fields, Celery configuration, database pool tuning, logging levels, and Redis connection settings.
Singularity uses Pydantic Settings for configuration management. All settings are loaded from environment variables or a .env file at the project root.
Settings Class
config.settings.Settings
The Settings class inherits from pydantic_settings.BaseSettings. A module-level singleton settings is created at import time and shared across the entire application.
from singularity.config import settings
# Access any field
db_url = settings.database_url
env = settings.environmentSettings Fields
environmentstr= "dev"
database_urlstr= "postgresql+asyncpg://...localhost:5432/postgres"
celery_broker_urlstr= "redis://localhost:6379/0"
celery_result_backendstr= "redis://localhost:6379/0"
jwt_secretstr= "dummy_value"
rpc_base_urlstr= "http://localhost:8000"
Pydantic Config
env_filestr= ".env"
env_file_encodingstr= "utf-8"
Example .env File
ENVIRONMENT=dev
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/mydb
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/1
JWT_SECRET=your-secret-key-here
RPC_BASE_URL=http://localhost:8000The default values for database_url, celery_broker_url, and jwt_secret are placeholder values. Always set these via environment variables or .env in any non-local environment.
Adding Custom Settings
Extend the Settings class in singularity/config.py to add your own fields:
class Settings(BaseSettings):
# ... existing fields ...
# Custom fields
stripe_api_key: str = ""
stripe_webhook_secret: str = ""
max_upload_size: int = 10_485_760 # 10MB
billing_host_url: str = "http://localhost:8001"
billing_api_key: str = ""All custom fields automatically support environment variable loading. The env var name is the uppercased field name (e.g. STRIPE_API_KEY).
Celery Configuration
common.q
Celery is configured in singularity/common/q.py. The configuration is applied via celery_app.conf.update().
Configuration Keys
task_serializer"json"
accept_content["json"]
result_serializer"json"
timezone"UTC"
enable_utcTrue
task_track_startedTrue
task_time_limit3600
worker_pool"threads" / "prefork"
worker_concurrency2
worker_prefetch_multiplier1
beat_scheduler"redbeat.RedBeatScheduler"
redbeat_redis_urlsettings.celery_broker_url
redbeat_key_prefix"celery:beat:"
broker_connection_retry_on_startupTrue
beat_schedule{}
The singularity tasks worker CLI command lets you override worker_pool (--pool) and worker_concurrency (--concurrency) at runtime without changing the configuration file.
Database Pool Configuration
database.postgres
Singularity configures two SQLAlchemy engines: an async engine for FastAPI endpoints and a sync engine for Celery tasks.
Async Engine (FastAPI)
poolclassAsyncAdaptedQueuePool
pool_size20
pool_timeout3600
pool_pre_pingTrue
echoFalse
Sync Engine (Celery Workers)
poolclassQueuePool
pool_size100
max_overflow200
pool_timeout30
pool_pre_pingTrue
echoFalse
Session Configuration
Both session factories use expire_on_commit=False to allow access to object attributes after a commit without requiring a refresh.
# Async session (for services)
async_session = async_sessionmaker[AsyncSession](async_engine, class_=AsyncSession, expire_on_commit=False)
# Sync session (for Celery tasks)
sync_session = sessionmaker[Session](sync_engine, class_=Session, expire_on_commit=False)get_db() Dependency
The get_db() async generator is available as a FastAPI dependency for direct use in route handlers:
from singularity.db import get_db
@router.get("/users")
async def list_users(db: AsyncSession = Depends(get_db)):
result = await db.execute(select(User))
return result.scalars().all()The sync database URL is derived automatically from settings.database_url by replacing postgresql+asyncpg:// with postgresql://. No separate env var is needed.
Logging Configuration
common.logger
Singularity uses Loguru for structured logging. The logging level and targets are determined by the environment setting.
Logging Levels per Environment
| dev | beta | prod | |
|---|---|---|---|
| Level | DEBUG | DEBUG | INFO |
| Targets | stderr + file | stderr | stderr |
| Details | Console + logs/app.log (10 MB rotation) | Console-only debug logging | Console-only, info level and above |
Usage
from singularity.common.logger import log as logger
# Structured logging
logger.info("Task completed", task_name="send_email", duration_ms=150)
logger.error("Payment failed", order_id="123", error="Insufficient funds")
logger.debug("RPC call", caller="orders", target="payments", method="charge")Loguru supports rich contextual logging via keyword arguments. Each key-value pair becomes a structured field in the log output.
Redis Connection Settings
Redis is used for three purposes in Singularity:
| Purpose | Config Field | Redis Key Pattern |
|---|---|---|
| Celery broker (task queue) | celery_broker_url | Managed by Celery |
| Celery result backend | celery_result_backend | Managed by Celery |
| RPC service discovery | celery_broker_url | singularity:rpc:services:{name}, singularity:rpc:spec |
| RedBeat scheduler | celery_broker_url | celery:beat:* |
| WebSocket notifications | celery_broker_url | Pub/sub channel: task_notifications |
All Redis connections currently share the same URL (celery_broker_url). If you need to separate them (e.g. different Redis instances for broker vs. RPC), you can add additional fields to the Settings class and update the relevant modules.
RPC Redis Keys
| Key | TTL | Content | Set By |
|---|---|---|---|
singularity:rpc:services:{name} | 60s | JSON spec for a single service (base_url, blacklist, methods) | RPCRegistry.publish_to_redis() |
singularity:rpc:spec | 60s | Full RPC spec for all local services | RPCRegistry.publish_to_redis() |
RPC Heartbeat
| Setting | Value | Description |
|---|---|---|
| Interval | 30 seconds | How often the heartbeat refreshes Redis keys |
| TTL | 60 seconds | Time-to-live for each Redis key |
| Disable flag | --no-heartbeat | CLI flag on app.py that sets SINGULARITY_NO_HEARTBEAT=1 |
If the heartbeat is disabled, RPC keys will expire after 60 seconds and remote services will no longer be discoverable.
Environment Variable Summary
Complete list of all environment variables recognized by Singularity: