Python Client

MOSTLY AI Python client

Use the MOSTLY AI Python client to train generators, generate synthetic data, connect to data sources, share data with your team, and much more.

IntentPrimitive
Train a Generator on tabular or language datag = mostly.train(config)
Generate any number of synthetic data recordssd = mostly.generate(g, config)
Live probe the generator on demanddf = mostly.probe(g, config)
Connect to any data source within your orgc = mostly.connect(config)
💡

For a complete API reference, see the Python Client package documentation (opens in a new tab).

Installation

You can install the latest release of mostlyai via pip:

bash
pip install -U mostlyai

Get an API key

To use the Python client, you need an API key. Get your API key for the REST API or Python client from your user profile menu.

Steps

  1. Hover over the profile menu in the upper right and select API key. MOSTLY AI - Python client - From the Profile menu select API key
  2. Click Generate API Key. MOSTLY AI - Python client - Click Generate API key

What's next

Your key is immediately copied to your clipboard. You can now use it for the REST API or to instantiate your Python client.

python
from mostlyai import MostlyAI
mostly = MostlyAI(api_key="mostly-**********")

Examples

As you explore the Generators, Synthetic datasets, and Connectors pages, you will find code snippets that show how to accomplish a task with the Python client. Use the Python and UI tabs to switch between the code snippets and the UI steps.

Python client and UI tabs

Quick Start

python
import pandas as pd
from mostlyai import MostlyAI
 
# initialize client
mostly = MostlyAI(
    api_key='INSERT_YOUR_API_KEY',   # or set env var `MOSTLYAI_API_KEY`
    base_url='https://app.mostly.ai' # or set env var `MOSTLYAI_BASE_URL`
)
 
# train a generator
df = pd.read_csv('https://github.com/mostly-ai/public-demo-data/raw/dev/census/census.csv.gz')
g = mostly.train(data=df)
 
# probe for some samples
syn = mostly.probe(g, size=10)
 
# generate a synthetic dataset
sd = mostly.generate(g, size=2_000)
 
# start using it
sd.data()