Skip to content

Local development

Run tiktok-api on your machine without Docker.

Prerequisites

Requirement Notes
Python 3.10+ CI and Dockerfile use 3.10
AWS credentials Secrets Manager + SSM for /stg/... paths
fs_config Git dependency in requirements.txt

Setup

cd tiktok-api
python3.10 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt   # tests

Verify AWS:

aws sts get-caller-identity

Run the API

export ENVIRONMENT=stg
python main.py

Server: http://0.0.0.0:8080 with Uvicorn reload enabled.

  • OpenAPI UI: http://127.0.0.1:8080/docs
  • Health: http://127.0.0.1:8080/api/status
  • Cache status: http://127.0.0.1:8080/api/cache/status

Unset ENVIRONMENT defaults to production

config/cfg.py uses prd when ENVIRONMENT is missing. Always set ENVIRONMENT=stg locally.

Authentication locally

Protected routes need header x-api-key with the staging key from Secrets Manager /{env}/tiktok-api/admin-api-keys (get_key for GET, post_key for mutations).

Tests

python -m pytest tests -q

Unit tests mock AWS/MySQL/S3 (tests/conftest.py). Integration tests are opt-in:

export ENVIRONMENT=stg
export TIKTOK_INTEGRATION_DB=1
python -m pytest tests/integration -m integration

IDE debugging

Field Value
Script main.py
Working directory Repo root
Env vars ENVIRONMENT=stg

S3 uploads locally

boto3 uses your IAM principal — no keys in config. You need s3:PutObject on the staging bucket (assets-stg.dadsnews.com).

Docker (optional)

cp .env.example .env   # ENVIRONMENT=stg for safe local compose
docker compose up --build

Prefer python main.py for faster iteration during development.