Environment Setup
Configuring environment variables for the Zyeta backend
The Zyeta backend uses environment variables for configuration. This guide explains how to set up these variables for development and production environments.
Environment File (.env)
Create a .env
file by copying the provided .env.local
template:
The .env
file contains sensitive information and should never be committed to version control. Note that it’s already included in the .gitignore
file.
Required Environment Variables
Based on the application’s settings module, the following environment variables are required:
Environment Variable Details
Application Settings
- APP_NAME: Name of your application
- ENVIRONMENT: Current environment (dev, beta, prod)
Security
- JWT_SECRET: Secret key for signing JWT tokens
- MASTER_API_KEY: Master API key for administrative access
- JWT_EXPIRE_MINUTES: JWT token expiration time in minutes
Database
-
DATABASE_URL: Connection string for PostgreSQL database
Format:
postgresql+asyncpg://user:password@host:port/database
Examples:
- Local Docker:
postgresql+asyncpg://postgres:mysecretpassword@localhost:5432/postgres
- Supabase:
postgresql+asyncpg://postgres:password@db.izufeytmzeanvqoyckwp.supabase.co:5432/postgres
- Local Docker:
External Services
- OPENAI_API_KEY: API key for OpenAI services
- ANTHROPIC_API_KEY: API key for Anthropic AI services
- RESEND_API_KEY: API key for Resend email service
- FIRECRAWL_API_KEY: API key for Firecrawl service
Frontend
- FRONTEND_URL: URL of the frontend application
Storage
- S3_BUCKET: Name of the S3 bucket for storage
- S3_ACCESS_KEY: Access key for S3
- S3_SECRET_KEY: Secret key for S3
- S3_ENDPOINT: Endpoint URL for S3 service
- PUBLIC_S3_BUCKET: Name of the public S3 bucket
Payment
- STRIPE_SECRET_KEY: Secret key for Stripe
- STRIPE_PUBLISHABLE_KEY: Publishable key for Stripe
- STRIPE_WEBHOOK_SECRET: Webhook secret for Stripe
Task Queue
- CELERY_BROKER_URL: URL for Celery broker (Redis)
- CELERY_RESULT_BACKEND: URL for Celery result backend (Redis)
Knowledge Base
- KB_SETTINGS_VERSION: Version of knowledge base settings
Sandbox
- PYTHON_SANDBOX_TESTING_URL: URL for Python sandbox testing
Alembic Configuration
The project includes an alembic.copy.ini
template that you should copy to create your own alembic.ini
:
Then update the sqlalchemy.url
field in alembic.ini
to match your database connection string. Note that you need to escape percent signs (%
) with another percent sign (%%
):
Environment-Specific Configuration
Development Environment
For development, you can use local services:
Testing Environment
For testing, use separate databases and services:
Production Environment
For production, use secure, production-grade services:
Loading Environment Variables
The application uses Python’s dotenv
package to load environment variables from the .env
file. The settings are loaded using Pydantic’s BaseSettings
class, which provides type validation and default values.
Accessing Settings in Code
The application uses a singleton pattern for settings. Import the settings
object to access environment variables:
Keeping Secrets Secure
Never commit sensitive information like API keys or database passwords to version control. Always use environment variables or secure secret management solutions.
Recommendations for Secret Management
- Development: Use local
.env
files - CI/CD: Use your CI/CD provider’s secret management
- Production: Use a secret manager like AWS Secrets Manager or HashiCorp Vault