Environment:869413421 Ai moive studio Backend Python Stack
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Backend, Web_API |
| Last Updated | 2026-10-23 14:00 GMT |
Overview
Python 3.11+ async backend stack with FastAPI, SQLAlchemy (asyncpg), Celery, Redis, PostgreSQL, and MinIO for the AICG content distribution platform.
Description
The backend runs on Python >= 3.11 with FastAPI as the web framework, SQLAlchemy 2.0 with async sessions (via asyncpg), Alembic for migrations, Celery with Redis broker for async task processing, and MinIO for object storage. The stack uses Pydantic v2 settings for configuration, LangGraph for AI agent orchestration, and Pillow for image processing. Optional GPU support includes CUDA cuBLAS and cuDNN packages.
Usage
Use this environment for running the backend API server (uvicorn), Celery workers, and all backend services including text parsing, LLM prompt generation, image/audio/video generation, video synthesis, canvas studio, and Bilibili publishing. This is the foundational environment for all backend Implementation pages.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux / macOS / Windows | Cross-platform; WSL2 recommended for Windows |
| Hardware | 2GB+ RAM | 4GB+ recommended for video processing tasks |
| Disk | 20GB+ | PostgreSQL data, MinIO storage, temp video files |
| GPU | Optional | CUDA 12 for faster-whisper transcription (GPU optional dependencies) |
Dependencies
System Packages
- `postgresql` 15 (via Docker)
- `redis` 7 (via Docker)
- `minio` (via Docker)
- `ffmpeg` >= 4.4 (see Environment:869413421_Ai_moive_studio_FFmpeg)
- `biliup` (see Environment:869413421_Ai_moive_studio_biliup_CLI)
Python Packages
- `fastapi` >= 0.104.0
- `uvicorn[standard]` >= 0.24.0
- `sqlalchemy[asyncio]` >= 2.0.0
- `asyncpg` >= 0.29.0
- `alembic` >= 1.12.0
- `redis` >= 5.0.0
- `celery` >= 5.3.0
- `pydantic` >= 2.4.0
- `pydantic-settings` >= 2.0.0
- `python-jose[cryptography]` >= 3.3.0
- `passlib[bcrypt]` >= 1.7.4
- `minio` >= 7.2.0
- `httpx` >= 0.25.0
- `openai` >= 2.8.1
- `pillow` >= 10.0.0
- `cryptography` >= 41.0.0
- `langgraph` >= 0.2.0
- `faster-whisper` >= 1.2.1
- `aiofiles` >= 23.2.1
- `ebooklib` >= 0.20
- `beautifulsoup4` >= 4.14.2
- `python-docx` >= 1.2.0
- `python-magic` >= 0.4.27 (Linux/macOS) / `python-magic-bin` >= 0.4.14 (Windows)
Credentials
The following environment variables must be set in `.env`:
- `DATABASE_URL`: PostgreSQL async connection string (default: `postgresql+asyncpg://aicg_user:aicg_password@localhost:5432/aicg_platform`)
- `REDIS_URL`: Redis connection string (default: `redis://localhost:6379/0`)
- `CELERY_BROKER_URL`: Celery broker URL (defaults to REDIS_URL)
- `CELERY_RESULT_BACKEND`: Celery result backend (defaults to REDIS_URL)
- `JWT_SECRET_KEY`: JWT signing key (must change in production)
- `API_KEY_ENCRYPTION_KEY`: Fernet encryption key for API key storage (must set in production)
- `MINIO_ENDPOINT`: MinIO endpoint (default: `localhost:9000`)
- `MINIO_ACCESS_KEY`: MinIO access key (default: `minioadmin`)
- `MINIO_SECRET_KEY`: MinIO secret key (default: `minioadmin`)
- `MINIO_PUBLIC_URL`: Optional public-facing MinIO URL for presigned URLs
- `ENVIRONMENT`: One of `development`, `testing`, `staging`, `production`
Quick Install
# Start infrastructure (PostgreSQL, Redis, MinIO)
./scripts/start.sh
# Install Python dependencies
cd backend
uv sync
# Apply database migrations
alembic upgrade head
# Start development server
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000
Code Evidence
Configuration from `config.py:13-76`:
class Settings(BaseSettings):
DATABASE_URL: str = Field(
default="postgresql+asyncpg://aicg_user:aicg_password@localhost:5432/aicg_platform",
env="DATABASE_URL"
)
REDIS_URL: str = Field(default="redis://localhost:6379/0", env="REDIS_URL")
CELERY_BROKER_URL: str = Field(default="redis://localhost:6379/0", env="CELERY_BROKER_URL")
JWT_SECRET_KEY: str = Field(default="your-super-secret-jwt-key-change-in-production", env="JWT_SECRET_KEY")
API_KEY_ENCRYPTION_KEY: Optional[str] = Field(default=None, env="API_KEY_ENCRYPTION_KEY")
MINIO_ENDPOINT: str = Field(default="localhost:9000", env="MINIO_ENDPOINT")
Environment validation from `config.py:126-132`:
@field_validator("ENVIRONMENT", mode="before")
@classmethod
def validate_environment(cls, v: str) -> str:
valid_envs = ["development", "testing", "staging", "production"]
if v not in valid_envs:
raise ValueError(f"ENVIRONMENT必须是以下之一: {valid_envs}")
return v
Encryption key warning from `encryption.py:42-51`:
encryption_key = settings.API_KEY_ENCRYPTION_KEY
if not encryption_key:
logger.warning(
"API_KEY_ENCRYPTION_KEY 未设置,使用临时密钥。"
"生产环境必须设置此环境变量!"
)
encryption_key = Fernet.generate_key().decode()
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `API_KEY_ENCRYPTION_KEY 未设置` | Fernet key not configured | Set `API_KEY_ENCRYPTION_KEY` env var with a Fernet key |
| `connection refused` on port 5432/6379/9000 | Infrastructure not started | Run `./scripts/start.sh` to start Docker services |
| `Session is already flushing` | Concurrent DB session access | Use independent sessions per worker (see Heuristic:869413421_Ai_moive_studio_Session_Isolation_For_Workers) |
| `JWT_SECRET_KEY` default warning | Production using default key | Set a secure `JWT_SECRET_KEY` in `.env` |
Compatibility Notes
- python-magic: Uses `python-magic-bin` on Windows and `python-magic` on Linux/macOS (platform-conditional in pyproject.toml).
- GPU Support: Optional `gpu` extras include `nvidia-cublas-cu12` and `nvidia-cudnn-cu12` for faster-whisper acceleration.
- Python Version: Requires >= 3.11. Tested on 3.11 and 3.12.
- Docker Compose: Infrastructure services (PostgreSQL, Redis, MinIO) run in Docker; the backend runs locally.
Related Pages
- Implementation:869413421_Ai_moive_studio_GatewayProvider
- Implementation:869413421_Ai_moive_studio_ProjectProcessingService_process_uploaded_file
- Implementation:869413421_Ai_moive_studio_TextParserService_parse_to_models
- Implementation:869413421_Ai_moive_studio_PromptService_generate_prompts_batch
- Implementation:869413421_Ai_moive_studio_ImageService_generate_images
- Implementation:869413421_Ai_moive_studio_AudioService_generate_audio
- Implementation:869413421_Ai_moive_studio_CanvasAssistantAgentFactory
- Implementation:869413421_Ai_moive_studio_EncryptionService