Mixpanel Python API Docs | dltHub

Build a Mixpanel-to-database pipeline in Python using dlt with automatic cursor support.

Last updated:

Mixpanel is a product analytics platform that collects and analyzes user event and profile data to provide insights and reporting. The REST API base URL is Query API base: https://mixpanel.com/api (EU: https://eu.mixpanel.com/api, IN: https://in.mixpanel.com/api) Raw Data Export base: https://data.mixpanel.com/api/2.0 (EU: https://data-eu.mixpanel.com/api/2.0, IN: https://data-in.mixpanel.com/api/2.0) Ingestion base: https://api.mixpanel.com (EU: https://api-eu.mixpanel.com, IN: https://api-in.mixpanel.com) Feature Flags API base: https://api.mixpanel.com/flags (EU: https://api-eu.mixpanel.com/flags, IN: https://api-in.mixpanel.com/flags) and Mixpanel uses service accounts (recommended) or project secrets/API keys; many endpoints require HTTP Basic auth with a service account or API secret..

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Mixpanel data in under 10 minutes.


What data can I load from Mixpanel?

Here are some of the endpoints you can load from Mixpanel:

ResourceEndpointMethodData selectorDescription
projects/api/app/projectsGETprojectsList projects for the account (returns object with "projects" array)
annotations/api/app/annotationsGETannotationsList annotations for a project (returns object with "annotations" array)
schemas/api/app/projects/{project_id}/schemasGETschemasList Lexicon schemas for project (returns object with "schemas" array)
engage/api/engageGETresultsQuery user profiles; response contains "results" array of profiles
export/api/2.0/exportGET(top-level NDJSON stream)Raw event export; returns newline-delimited JSON (top-level per-line event objects, not wrapped in an array)
cohorts/api/2.0/cohorts/listGETcohortsList cohorts for project (returns object with "cohorts" array)
funnels/api/2.0/funnelsGETfunnelsList saved funnels or query funnel reports (returns object with "funnels" array or report object)
jql/api/2.0/jqlPOST/GET (query)(varies)Run custom JQL queries (response is JSON array or object depending on script)
pipelines/api/2.0/nessie/pipelinesGETpipelinesList Data Pipelines (returns object with "pipelines" array)

How do I authenticate with the Mixpanel API?

Mixpanel supports Service Account authentication (username/password or key) for server-to-server access and HTTP Basic auth for many Query and Export endpoints (username = service account username or API secret, password blank). Some endpoints accept project tokens for client-side ingestion. Include Authorization via Basic auth (base64) or use service account credentials in headers as documented.

1. Get your credentials

  1. Log in to Mixpanel and go to Project Settings or Admin > Service Accounts. 2) Create a Service Account and assign project membership and roles. 3) Note the service account username and click to create/obtain a password or key. 4) For Export/Query API use the service account username as HTTP Basic username and the password (or project secret where applicable) as password (or leave password blank if using secret as username). 5) Store credentials securely.

2. Add them to .dlt/secrets.toml

[sources.mixpanel_source] service_account_username = "your_service_account_username" service_account_password = "your_service_account_password" project_id = "your_project_id"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Mixpanel API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python mixpanel_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline mixpanel_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset mixpanel_data The duckdb destination used duckdb:/mixpanel.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline mixpanel_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads engage and export from the Mixpanel API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def mixpanel_source(service_account_password=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "Query API base: https://mixpanel.com/api (EU: https://eu.mixpanel.com/api, IN: https://in.mixpanel.com/api) Raw Data Export base: https://data.mixpanel.com/api/2.0 (EU: https://data-eu.mixpanel.com/api/2.0, IN: https://data-in.mixpanel.com/api/2.0) Ingestion base: https://api.mixpanel.com (EU: https://api-eu.mixpanel.com, IN: https://api-in.mixpanel.com) Feature Flags API base: https://api.mixpanel.com/flags (EU: https://api-eu.mixpanel.com/flags, IN: https://api-in.mixpanel.com/flags)", "auth": { "type": "http_basic", "service_account_password": service_account_password, }, }, "resources": [ {"name": "engage", "endpoint": {"path": "api/engage", "data_selector": "results"}}, {"name": "export", "endpoint": {"path": "api/2.0/export"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="mixpanel_pipeline", destination="duckdb", dataset_name="mixpanel_data", ) load_info = pipeline.run(mixpanel_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("mixpanel_pipeline").dataset() sessions_df = data.engage.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM mixpanel_data.engage LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("mixpanel_pipeline").dataset() data.engage.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Mixpanel data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Troubleshooting

Authentication failures

If requests return 401/403, verify you are using a valid service account or project secret. For Query/Export endpoints use HTTP Basic auth (username = service account username or project secret) and password blank or service account password. Ensure the service account has project membership and required roles.

Rate limits

The Raw Export API is limited (documented: 60 queries/hour, 3 queries/second, max 100 concurrent). Exceeding limits returns HTTP 429. Throttle requests and implement exponential backoff.

Pagination and large exports

The Engage and Query APIs paginate results (responses include offsets or paging tokens and the results array). The Export API returns newline-delimited JSON for streaming large exports — parse line-by-line rather than expecting a JSON array.

Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Mixpanel?

Request dlt skills, commands, AGENT.md files, and AI-native context.