Skip to main content

TDD engine for Analytics Engineering — generate unit test data for SQL queries

Project description

MockSQL — Backend

FastAPI + LangGraph + CLI

Ce dossier contient le cœur de MockSQL : l'API REST, le graph LangGraph de génération de données, le CLI, et le package mocksql-ui (serveur web + assets React).


Quickstart local

Prérequis : Python ≥ 3.11, Poetry ≥ 1.8, un projet Google Cloud avec la facturation activée.

1. Authentification Google Cloud

gcloud auth application-default login
gcloud config set project <PROJECT_ID>

2. Variables d'environnement

cp .env.example .env   # puis compléter les valeurs

Variables minimales requises :

PROJECT_ID=<votre-projet-gcp>
GOOGLE_CLOUD_PROJECT=<votre-projet-gcp>
BQ_SCHEMA_BILLING_PROJECT=<votre-projet-gcp>
DEFAULT_MODEL_NAME=gemini-2.0-flash-lite
DUCKDB_PATH=data/mocksql.duckdb
SECRET_KEY=<générer avec : python -c "import secrets; print(secrets.token_hex(32))">
API_SECRET_KEY=<idem>
FRONT_URL=http://127.0.0.1:3000

3. Installation & lancement

python -m venv .venv

# Linux / macOS
source .venv/bin/activate

# Windows
.\.venv\Scripts\activate

pip install poetry && poetry install

# Lancer le serveur
uvicorn server:app --port 8080 --reload

L'API est accessible sur http://localhost:8080, le frontend sur http://localhost:3000 (voir ../front/README.md).


Commandes de développement

make style    # ruff check + ruff format --check + vulture (code mort)
make format   # ruff format + ruff check --fix (auto-correction)
make test     # pytest
make check    # style + test

Type checking :

poetry run mypy build_query/ app/

Packaging

MockSQL produit deux wheels indépendants :

Wheel Contenu
mocksql-*.whl CLI + LangGraph core (sans UI)
mocksql_ui-*.whl Serveur web + assets React bundlés

Builder les wheels

# CLI uniquement
make build-cli

# CLI + UI (build React inclus — Node.js 18+ requis)
make build-ui

Les wheels sont générés dans dist/.

Lancer l'UI depuis les wheels

pip install dist/mocksql-*.whl dist/mocksql_ui-*.whl
mocksql ui              # http://localhost:8080/static/
mocksql ui --port 4000
mocksql ui --no-browser

Déploiement

Variables d'environnement (production)

Voir .env.example pour la liste complète. En production (Cloud Run), les secrets sont gérés via Google Secret Manager ou les variables d'environnement du service.

Conteneurisation (Docker)

docker build -t mocksql-backend .
docker run -d -p 8080:8080 \
  -e PROJECT_ID=<votre-projet-gcp> \
  -e GOOGLE_APPLICATION_CREDENTIALS=/keys/sa.json \
  -v ~/keys:/keys \
  mocksql-backend

Google Cloud Run

1. Build & push

gcloud builds submit --tag gcr.io/${PROJECT_ID}/mocksql-backend .

2. Secrets

gcloud secrets create mocksql-env --data-file .env

3. Déploiement

gcloud run deploy mocksql-backend \
  --image gcr.io/${PROJECT_ID}/mocksql-backend \
  --region europe-west1 \
  --platform managed \
  --allow-unauthenticated \
  --memory 1Gi \
  --service-account mocksql-sa@${PROJECT_ID}.iam.gserviceaccount.com

Infrastructure Terraform

cd ../terraform
cp variables.example.tfvars my_variables.tfvars
# compléter project_id, region, etc.

terraform init
terraform apply --var-file=my_variables.tfvars

Rôles requis pour le compte de service Terraform :

  • Cloud SQL Admin
  • Project IAM Admin
  • Service Account Admin
  • Service Usage Admin
  • BigQuery Admin

Permissions PostgreSQL (si Cloud SQL)

-- Base mocksql
GRANT USAGE, CREATE ON SCHEMA public TO "mocksql@${project_id}.iam";
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO "mocksql@${project_id}.iam";
CREATE EXTENSION IF NOT EXISTS vector;

-- Base sqlmeshconf
GRANT USAGE, CREATE ON SCHEMA public TO "mocksql@${project_id}.iam";
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO "mocksql@${project_id}.iam";

Licence

Propriétaire — © 2025 Adel Skhiri. Contact : skhiriadel92@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mocksql-0.1.0.tar.gz (144.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mocksql-0.1.0-py3-none-any.whl (170.9 kB view details)

Uploaded Python 3

File details

Details for the file mocksql-0.1.0.tar.gz.

File metadata

  • Download URL: mocksql-0.1.0.tar.gz
  • Upload date:
  • Size: 144.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mocksql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a14d6051e1f1fc0d336df17436d21e48bb2a0beffe0bb34fed0e235a0464155
MD5 d9de71b526bbb4492bb86a3f94b87c8b
BLAKE2b-256 71ef9c83bcf706f7e7a3cf281370fefbe4506425029f0f68c9759c960dd4abc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mocksql-0.1.0.tar.gz:

Publisher: release.yml on skadel/mocksql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mocksql-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mocksql-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 170.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mocksql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b17e2054f5c0f0faf944f59271608a5fad419b3c8a762e12366254f12f24532e
MD5 45af66ebc753fd8ca1e2f41c689143ad
BLAKE2b-256 51a3e166bb611799824f53593983415f2b35369e0c2ccb44435020a67df4c3f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mocksql-0.1.0-py3-none-any.whl:

Publisher: release.yml on skadel/mocksql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page