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
Use the library in your script or in the command-line.
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"}
]
)
Command-Line Interface:
Usage: python -m mockaroo [OPTIONS] COMMAND [ARGS]...
Interact with the Mockaroo APIs ๐ฆ + ๐
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Commands โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ delete Delete a dataset from Mockaroo โ
โ types Get Mockaroo data types โ
โ upload Upload dataset to Mockaroo โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: python -m mockaroo types [OPTIONS]
Get Mockaroo data types
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --pager -P Page output. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: python -m mockaroo upload [OPTIONS] NAME INPUT_FILE
Upload dataset to Mockaroo
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ * NAME TEXT [required] โ
โ * INPUT_FILE PATH [required] โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: python -m mockaroo delete [OPTIONS] NAME
Delete a dataset from Mockaroo
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ * NAME TEXT [required] โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
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'}]
Mockaroo Types
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
Built Distribution
Hashes for mockaroo_python-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ab88e65cf15171e6c7908df61410b61cfc870f453b0e0ba4cf99f33c4ebffff |
|
MD5 | a4593bbaa95c411c93fa53e05d35d654 |
|
BLAKE2b-256 | 56d69c8930b6f1a0e933561579f2257861db6c8236a81fb58c4c6b4726ac6824 |