Files
privatestudio/README.md
T
Shaun KrugerandClaude Opus 5.5 b3b51f6cc5 Convert web service from FastAPI to Django 6.1
Replace the FastAPI/SQLAlchemy/Alembic web service with a Django project
laid out like cumorah-build: manage.py at the root, settings in the
privatestudio.settings package (base/dev/production), and a
privatestudio.studio app.

- Studio model owns a unique bucket_name; access is granted through
  membership in the studio's auth Group. Assets, profiles and jobs are
  scoped to a studio; API keys and S3 credentials stay per user.
- JSON API via Django Ninja under /api/ (profiles and transcode jobs now
  live under /api/studios/{bucket}/).
- S3-compatible interface as plain class-based views under /s3/,
  supporting bearer tokens and AWS v4 signatures.
- create_studio and create_key management commands replace ps-serve.
- Fresh Django initial migration; tests ported to Django TestCase.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 21:54:16 -07:00

5.2 KiB

Private Studio - Video Transcoding Web Service

A Django video transcoding management service. It provides S3-compatible file storage, API key authentication, and studio-based access control.

Features

  • Studios: each studio owns one S3 bucket. Members of the studio's Django group can access it.
  • S3-compatible interface: upload, download, delete and list objects with bearer tokens or AWS v4 signatures (works with boto3).
  • JSON API (Django Ninja): manage API keys, temporary S3 credentials, transcode profiles and transcode jobs. Interactive docs are at /api/docs.
  • Django admin for managing users, groups, studios and jobs.

Installation

Requires Python 3.12+.

pip install -e ".[dev]"

Quick Start

python manage.py migrate
python manage.py createsuperuser
python manage.py create_studio demo --name "Demo Studio" --group demo-team --add-user <username>
python manage.py create_key <username>
python manage.py runserver

create_key prints the API key once. Keep it secret.

To grant someone access to a studio, add them to the studio's group, either in the admin (/admin/) or with create_studio --add-user when the studio is created.

See README_SERVE.md for the full command guide.

Project Layout

manage.py
privatestudio/
  settings/base.py        # shared settings
  settings/dev.py         # default (DJANGO_SETTINGS_MODULE=privatestudio.settings.dev)
  settings/production.py  # env-driven production settings
  urls.py, wsgi.py, asgi.py
  studio/                 # Django app: models, API routers, S3 views, management commands
  transcode.py            # ps-transcode CLI (ffmpeg wrapper)

Configuration

Settings live in the privatestudio.settings package. Choose one with DJANGO_SETTINGS_MODULE:

  • privatestudio.settings.dev is the default. You can add overrides in an optional, git-ignored privatestudio/settings/local.py.
  • privatestudio.settings.production is configured from the environment variables below.
Variable Used by Description
STORAGE_PATH all File storage root (default <repo>/storage)
S3_CREDENTIAL_TTL_HOURS all Lifetime of /api/s3keys credentials (default 1)
DJANGO_TIME_ZONE all Time zone (default UTC)
SECRET_KEY production Django secret key
ALLOWED_HOSTS production Comma-separated host names
DATABASE_URL production Database URL parsed by dj-database-url (default SQLite db.sqlite3)
CORS_ALLOWED_ORIGINS production Comma-separated allowed CORS origins
SECURE_PROXY_SSL_HEADER production Set to trust X-Forwarded-Proto from a proxy

API Usage

All endpoints except /health need Authorization: Bearer <API_KEY>. The S3 endpoints also accept AWS v4 signatures made with credentials from /api/s3keys.

Account

Method Path Description
GET /api/userinfo User id, username, and the studios (buckets) the user can access
POST /api/keys Create an API key
GET /api/keys List your API keys
DELETE /api/keys/{id} Revoke an API key
POST /api/s3keys Create temporary S3 access/secret keys

S3-compatible storage

Method Path Description
PUT /s3/{bucket}/{key} Upload: either a raw body, or multipart with a file field
GET /s3/{bucket}/{key} Download
HEAD /s3/{bucket}/{key} Object size
DELETE /s3/{bucket}/{key} Delete
GET /s3/{bucket}?prefix=&delimiter= List objects
curl -X PUT -H "Authorization: Bearer $KEY" --data-binary @video.mp4 \
  http://localhost:8000/s3/demo/videos/video.mp4

With boto3 (AWS v4 signatures):

import boto3, requests
from botocore.config import Config

creds = requests.post("http://localhost:8000/api/s3keys",
                      headers={"Authorization": f"Bearer {KEY}"}).json()
s3 = boto3.client("s3", endpoint_url="http://localhost:8000/s3",
                  aws_access_key_id=creds["access_key"],
                  aws_secret_access_key=creds["secret_key"],
                  region_name="us-east-1",
                  config=Config(signature_version="s3v4", s3={"addressing_style": "path"}))
s3.upload_file("video.mp4", "demo", "videos/video.mp4")

Transcode profiles and jobs (per studio)

Method Path Body
POST /api/studios/{bucket}/profiles?name=<name> YAML profile definition (must contain profiles:)
GET /api/studios/{bucket}/profiles
GET /api/studios/{bucket}/profiles/{id}
POST /api/studios/{bucket}/transcode YAML job request
GET /api/studios/{bucket}/transcode?status=pending
GET /api/studios/{bucket}/transcode/{id}

The asset in a job request can be given as its key, its filename or its ID. The profile can be a profile name or an inline definition:

asset: videos/video.mp4
profile: hd-profile
curl -X POST -H "Authorization: Bearer $KEY" -H "Content-Type: application/yaml" \
  --data-binary @job.yaml http://localhost:8000/api/studios/demo/transcode

Storage

Files are stored under STORAGE_PATH/<bucket_name>/<key>. Keys that resolve outside the bucket directory are rejected.

Testing

pytest