Skip to content

Python SDK

The Python SDK is datamaker-py, the same SDK that runs inside DataMaker scenarios, so anything you write locally moves into a scenario unchanged.

Install

Terminal window
pip install "git+https://github.com/automators-com/datamaker-py.git"

The import name is datamaker:

from datamaker import DataMaker, Template

Authenticate

from datamaker import DataMaker
dm = DataMaker(api_key="sk-...") # explicit
# dm = DataMaker() # inside a scenario the env is pre-populated

Inside a scenario the worker sets the context env vars for you (DATAMAKER_PROJECT_ID, DATAMAKER_TEAM_ID, DATAMAKER_SCENARIO_ID), so you can construct DataMaker() with no arguments.

Define a template and generate

A Template is a name, a quantity, and a list of fields. Each field has a name, a type, and optional options:

from datamaker import DataMaker, Template
dm = DataMaker()
template = Template(
name="Customer",
quantity=100,
fields=[
{"name": "first_name", "type": "First Name"},
{"name": "last_name", "type": "Last Name"},
{
"name": "email",
"type": "Derived",
"options": {"value": "{{first_name}}.{{last_name}}@example.com"},
},
],
)
rows = dm.generate(template)

Typed field helpers

Instead of raw dicts you can use the field classes, such as WordsField, UUIDField, NumberField, FloatField, BooleanField, AIField, CustomField:

from datamaker import Template
from datamaker.template import NumberField, AIField, CustomField
template = Template(
name="Order",
quantity=50,
fields=[
NumberField("quantity", options={"min": 1, "max": 10}),
AIField("product_name", prompt="a realistic consumer electronics product name"),
CustomField("status", values=["new", "shipped", "returned"]),
],
)

Generate from an existing template

If the template already exists in the project, generate by id:

rows = dm.generate_from_template_id("<template-id>", quantity=100)

Create and manage resources

The client exposes flat methods for the core resources. For example:

dm.create_template(template_data, project_id="proj_...", team_id="team_...")
dm.create_connection(connection_data)
dm.get_connections()

See the REST reference and the SDK’s autocomplete types for the full CRUD surface and the exact method shapes.

Export

Push generated rows into a target:

dm.export_to_database(export_data) # to a database connection
dm.export_to_rest(export_data) # to a REST endpoint

See Connections for configuring the targets.

Scenario files

Inside a scenario, read and write files that ride along with the run:

dm.create_scenario_file(...)
dm.download_scenario_file(...)

Errors

The SDK raises DataMakerError:

from datamaker import DataMaker
from datamaker.error import DataMakerError
try:
rows = dm.generate_from_template_id("missing-id", quantity=100)
except DataMakerError as e:
print("DataMaker call failed:", e)

Source

  • GitHub: automators-com/datamaker-py
  • The repo publishes generated autocomplete types on every push to main. Use those for the complete, current method surface.