On this page
Database Seeding
Point Misata at an existing database schema and fill a dev or staging environment with production-like data, FK ordering handled automatically.
Introspect and seed#
Python
from misata import schema_from_db, generate_from_schema, seed_database
# Read your live schema: no column definitions needed
schema = schema_from_db("postgresql://user:pass@localhost/myapp")
# Generate and insert into a dev copy, in one transaction
report = seed_database(schema, "postgresql://user:pass@localhost/myapp_dev")
print(report.table_rows)
# Or keep the rows in memory as DataFrames
tables = generate_from_schema(schema)CLI workflow#
Shell
# Step 1: introspect into a YAML file
misata init --db postgresql://user:pass@localhost/myapp
# Step 2: review or edit misata.yaml, then seed
misata generate --db-url postgresql://user:pass@localhost/myapp_dev --db-createSQLAlchemy models#
Python
from misata import seed_from_sqlalchemy_models
from myapp.models import Base
report = seed_from_sqlalchemy_models(
Base,
db_url="sqlite:///test.db",
row_count=500,
create_tables=True,
)Read back from a database#
Python
from misata import load_tables_from_db
tables = load_tables_from_db("postgresql://user:pass@localhost/myapp_dev")
print(tables["orders"].head())Supported databases#
- PostgreSQL:
pip install "misata[db]"(psycopg3) - MySQL / MariaDB: via SQLAlchemy
pip install "misata[orm]" - SQLite: built-in, no extras needed
- Any SQLAlchemy-compatible engine
FK insert order
Misata performs a topological sort on the relationship graph before inserting, so parent rows always exist before child rows are inserted. Circular FK references raise a
ConfigurationError.
Prefer generating data visually?
Misata Studio lets you turn natural language prompts into relational schemas with exact outcome invariants, live preview tables, and one-click database seeding without writing code.

