Framework

Python Test Data Generation with MockHero

The Pattern

Hit MockHero with requests, receive JSON, and let your ORM do the insert. No Faker.py maintenance, no per-test factories.

import os, requests

def mock(tables, seed=None):
  body = {"tables": tables}
  if seed is not None: body["seed"] = seed
  return requests.post(
    "https://api.mockhero.dev/api/v1/generate",
    json=body,
    headers={"x-api-key": os.environ["MOCKHERO_API_KEY"]}
  ).json()

data = mock([
  {"name": "users", "count": 50, "fields": [
    {"name": "id", "type": "uuid"},
    {"name": "email", "type": "email"},
    {"name": "full_name", "type": "full_name"}
  ]},
  {"name": "orders", "count": 200, "fields": [
    {"name": "id", "type": "uuid"},
    {"name": "user_id", "type": "ref", "ref": "users.id"},
    {"name": "total", "type": "price"}
  ]}
], seed=42)

Why Not Just Use Faker.py or Mimesis?

  • Relational data is declarative, not a hand-written loop.
  • Same seed gives identical data across machines and CI.
  • Data flows through one endpoint, so a Go service and a Python service can share identical test rows.

Get Started

Grab a free API key.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles