Skip to main content

mockaroo-python

PyPI Changelog

A Python wrapper for the Mockaroo API 🦘 + 🐍.

Installation

Install this tool using pip:

pip install mockaroo-python

Prerequisites

To use this library, you'll need an API key from the Mockaroo website.

Set your key as an environment variable:

export MOCKAROO_API_KEY=<api_key>

or pass it to the Client class as an argument:

client = Client(api_key="api_key")

Usage

Use the library in your Python script or from the command-line.

Command-Line:

For help, run:

mockaroo --help

You can also use:

python -m mockaroo --help

Generate a dataset:

mockaroo gen Person # your own schema in Mockaroo

[
    {
        "id": 1,
        "first_name": "Burch",
        "last_name": "Minichi"
    },
    {
        "id": 2,
        "first_name": "Val",
        "last_name": "Curzon"
    },
    {
        "id": 3,
        "first_name": "Poppy",
        "last_name": "Pallant"
    }
]

Write data to a file format (JSON, CSV, TXT, XML, or SQL):

mockaroo gen Person --count 5 >> people.json

Upload a file to Mockaroo:

mockaroo upload customers customers.csv

Delete a file:

mockaroo delete customers

Check the available Mockaroo types:

mockaroo types

Python Script:

from mockaroo import Client

# Initialize the client with your API key
client = Client(api_key="your_api_key_here")
# Or set an enviornment variable. `export API_KEY=your_api_key_here`
client = Client()

# Fetch available types from Mockaroo
types = client.types()

# Upload a dataset ('csv' or 'txt') to Mockaroo
client.upload(name="name_of_dataset", path="/path/to/file.csv")

# Remove a dataset from Mockaroo
client.delete(name="name_of_dataset")

# Generate data using a predefined schema
data = client.generate(schema="name_of_schema")

# Alternatively, specify fields to generate custom data
data = client.generate(
    fields=[
        {"name": "city", "type": "City"},
        {"name": "street_name", "type": "Street Name"}
    ]
)

Ways to Generate Mockaroo Datasets

Using Predefined Schemas

To generate data based on a schema you've created, specify the schema name as an argument.

Example:

from mockaroo import Client

client = Client()

data = client.generate(schema="Person")

print(data)
{'id': 1, 'first_name': 'Patrizius', 'last_name': 'Van'}

Using Custom Fields

Pass a list of field definitions to generate mock data with custom fields. For a full list of available types, see the Official API Reference Page.

Example:

result = client.generate(
    count=2, 
    fields=[
        {
            "name": "id", 
            "type": "Row Number"
        }, 
        {
            "name":"transactionType",
            "type": "Custom List", 
            "values": ["credit","debit"]
        }
    ]
)
print(result)
[{'id': 1, 'transactionType': 'credit'}, {'id': 2, 'transactionType': 'debit'}]

Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

cd mockaroo-python
poetry install

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Metadata

Release files for mockaroo-python 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mockaroo-python 3.0.0
File Size Uploaded Provenance Actions
mockaroo_python-3.0.0.tar.gz 8.9 kB Without provenance Details for mockaroo_python-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mockaroo-python 3.0.0
File Interpreter ABI Platform Actions
mockaroo_python-3.0.0-py3-none-any.whl Python 3 none any Details for mockaroo_python-3.0.0-py3-none-any.whl

Total release size: 18.4 kB

Release files / mockaroo_python-3.0.0.tar.gz

Download URL mockaroo_python-3.0.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
16f4161ad0fb6c068cb49b8891cc19fab8cd80895f0906d9eaecef040c80af1d
BLAKE2b-256 checksum
How to use checksums
9ef7f29ba81daf3c479b17a708d2bf1c7cffe849cd0f0605a6ae6da9f36febef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.1 Darwin/23.4.0

Release files / mockaroo_python-3.0.0-py3-none-any.whl

Download URL mockaroo_python-3.0.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7a0d197d58d817f88afee77e620d438f0e9e1649d384370f0456b852c277414
BLAKE2b-256 checksum
How to use checksums
e57ef2f60fd8b2bd5080107c6623da6d07278e8db06f0d74b4a0ba3abf6804cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.1 Darwin/23.4.0

Security for mockaroo-python 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page