This project indexes Nostr events and exposes them via a FastAPI service.
- Ensure Docker and Docker Compose are installed.
- Copy the provided
docker-compose.ymland start the services:
docker-compose up --buildEnsure you have a indexer/config.json file (or copy from indexer/config.json.example) specifying your relay list; this file will be mounted into the indexer container.
The API will be available at http://localhost:8008.
The web UI will be available at http://localhost:8080.
The indexer service will also be started, connecting to relays and populating the database.
The application reads PostgreSQL connection details from environment variables. When using the provided docker-compose.yml, these are set automatically:
PGDATABASE– database name (default:nostr)PGUSER– database user (default:nostr)PGPASSWORD– database password (default:nostr)PGHOST– PostgreSQL host (default:dbin Docker)PGPORT– PostgreSQL port (default:5432)RELAY_CONFIG_PATH– path to indexer relay config file (default:config.json)APP_CONFIG_PATH– path to general application JSON config file for hierarchical overrides (default:config.json)HEALTH_ENABLED– enable health endpoint (true/false, default:true)METRICS_ENABLED– enable metrics endpoint (true/false, default:true)LOG_LEVEL– logging level (e.g.,INFO, default:INFO)DB_LOG_LEVEL– PostgreSQL server log severity threshold (debug,info,notice,warning,error, default:warning)DB_LOG_STATEMENT– level of statement logging (none,ddl,mod,all, default:none)
EVENT_BATCH_SIZE– number of events to batch before database write (default:100)EVENT_BATCH_INTERVAL– max seconds to wait for batch before write (default:1.0)WORKER_POOL_SIZE– number of concurrent batch worker tasks (default:4)CIRCUIT_BREAKER_FAILURE_THRESHOLD– consecutive failures before opening circuit breaker (default:5)CIRCUIT_BREAKER_RECOVERY_TIMEOUT– seconds to wait before half-open state (default:60)RATE_LIMIT_ENABLED– enable API rate limiting (true/false, default:false)RATE_LIMIT_REQUESTS_PER_MINUTE– max requests per IP per minute (default:60)MAX_EVENT_QUERY_LIMIT– maximum allowedlimitparameter for/api/events(default:500)
-
CACHE_ENABLED– enable in-memory caching for expensive queries (true/false, default:false) -
CACHE_TTL_SECONDS– TTL (in seconds) for cached responses (default:60) -
CACHE_MAXSIZE– maximum number of entries in the cache (default:128) -
USE_MATERIALIZED_VIEWS– enable reading from materialized views for stats endpoint (true/false, default:false) -
MATVIEW_REFRESH_INTERVAL_SECONDS– seconds between periodic refresh of materialized views (0to disable, default:0) -
PG_POOL_MIN_SIZE– minimum number of connections in the database connection pool (default:1) -
PG_POOL_MAX_SIZE– maximum number of connections in the database connection pool (default:10) -
CONFIG_HOT_RELOAD_ENABLED– enable runtime hot-reloading of the relay config file (true/false, default:false) -
CONFIG_HOT_RELOAD_DEBOUNCE_SECONDS– debounce interval for config file reload in seconds (default:1.0) -
METRICS_SERVER_ENABLED– start Prometheus metrics server for indexer (true/false, default:false) -
METRICS_SERVER_PORT– port for Prometheus metrics server (default:8000) -
METRICS_REFRESH_INTERVAL_SECONDS– seconds between metrics updates (default:5.0) -
REQUEST_MAX_SIZE_BYTES– maximum request size in bytes for API requests (0to disable, default:0) -
MAX_QUERY_LENGTH– maximum length of text search queryq(default:500) -
API_AUTH_ENABLED– require Bearer token authentication for all API endpoints (true/false, default:false) -
API_AUTH_TOKEN– shared secret token for Bearer authentication when enabled (must be non-empty ifAPI_AUTH_ENABLEDistrue, default: empty)
You can override them by editing docker-compose.yml or providing your own environment file.
See api/api_documentation.md for API usage examples.
A simple search interface inspired by early-day Google is available at http://localhost:8080. Enter a query using Google-style filters (e.g., bitcoin kind:1 tag:e:some_event_id since:2025-06-01) to search events. Supported filters:
pubkey:<hex_or_npub>filter by author public keyrelay:<url>filter by relay URLkind:<number>filter by event kindsince:<timestamp_or_ISO>anduntil:<timestamp_or_ISO>filter by creation timetag:<key>:<value>filter by tag key:value pairs (repeatable)limit:<number>andoffset:<number>for pagination- free text terms for full-text content search
- prefix
-to any filter or term to exclude matching events (e.g.,-"bitcoin",-kind:1)
Nostr Harvester indexes events from a list of Nostr relays and exposes them through a small FastAPI service. It stores events in PostgreSQL and keeps track of which relay each event came from.
Each service has its own Python dependencies:
# Install API service dependencies
pip install -r api/requirements.txt
# Install Indexer service dependencies
pip install -r indexer/requirements.txtOptionally, install test dependencies:
pip install -e .[test]Start the API using Uvicorn:
uvicorn api.api_fastapi:app --reloadStart the indexer (ensure indexer/config.json is present with your relay list):
python -m indexer.nostr_indexer