A Python Library for interacting with Mockaroo APIs 🐍 + 🦘
Project description
Mockaroo API Python Library 🐍 + 🦘
A Python library for the Mockaroo APIs. Use this library to generate mock data for testing, simulations, and more.
Installation
Install from PyPl:
pip install mockaroo-python
Install from the GitHub Repository:
pip install git+https://github.com/Scarvy/mockaroo-python.git
Install from Local Source:
- Clone the repository:
git clone https://github.com/Scarvy/mockaroo-python.git
- Navigate to the cloned directory:
cd mockaroo-python
- Install the package:
pip install .
Prerequisites
To use this library, you'll need an API key from Mockaroo website.
Usage
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"}
]
)
Generate Dataset
Using Predefined Schemas
To generate data based on a schema you've created on Mockaroo's website, 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 data with custom fields. For a full list of available types, see the, see API Reference.
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'}]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mockaroo_python-1.1.0.tar.gz
(10.6 kB
view hashes)
Built Distribution
Close
Hashes for mockaroo_python-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7efc7931411d53e18a0cfb35b0baac25c6e05088f9d768199aa04f96058b3f23 |
|
MD5 | a96272959da481876e0018314eaf660f |
|
BLAKE2b-256 | ad616bac5d2a9d62a6e33c58483ea434d478946661e8110a4462126b54679e11 |