Custom faker type extensions for datacraft package
Project description
datacraft-faker
Custom plugin for datacraft to wrap the faker python module
Usage
The datacraft-faker
module adds a faker
Field Spec type to datacraft. This type allows a user to reference the
various data generation methods from faker in their Data Specs. For example:
{
"id": {"type": "uuid"},
"time:date.iso": {},
"name": {"type": "faker", "data": "name"},
"dob:faker": "date_of_birth"
}
The above example uses two built in datacraft types uuid
and date.iso
and two faker ones. The record generated for
this spec will look something like:
{
"id": "ad8f5737-59f9-48e3-bf4f-ed4deb357d0a",
"time": "2024-07-18T19:57:17",
"name": "Kimberly Wright",
"dob": "1979-06-27"
}
There type for the field will always be faker
. The data
element of the spec is where you define the method name
that generates the data of interest. Here are a bunch of examples:
Faker method | Spec Example |
---|---|
fake.name() | {"name": {"type": "faker", "data": "name"}} |
fake.address() | {"address": {"type": "faker", "data": "address"}} |
fake.email() | {"email": {"type": "faker", "data": "email"}} |
fake.phone_number() | {"phone_number": {"type": "faker", "data": "phone_number"}} |
fake.company() | {"company": {"type": "faker", "data": "company"}} |
fake.date_of_birth() | {"date_of_birth": {"type": "faker", "data": "date_of_birth"}} |
fake.text() | {"text": {"type": "faker", "data": "text"}} |
fake.city() | {"city": {"type": "faker", "data": "city"}} |
fake.state() | {"state": {"type": "faker", "data": "state"}} |
fake.zipcode() | {"zipcode": {"type": "faker", "data": "zipcode"}} |
Note that datacraft has a shorthand notation that works well for faker specs:
Faker method | Shorthand Spec |
---|---|
fake.name() | {"name:faker": "name"} |
fake.address() | {"address:faker": "address"} |
fake.email() | {"email:faker": "email"} |
fake.phone_number() | {"phone_number:faker": "phone_number"} |
fake.company() | {"company:faker": "company"} |
fake.date_of_birth() | {"date_of_birth:faker": "date_of_birth"} |
fake.text() | {"text:faker": "text"} |
fake.city() | {"city:faker": "city"} |
fake.state() | {"state:faker": "state"} |
fake.zipcode() | {"zipcode:faker": "zipcode"} |
Locales
Faker allows the ability to specify one or more locales to use for data generation. To configure this with a faker
Field Spec, add the config option locale
:
{
"name": {
"type": "faker",
"data": "name",
"config": {
"locale": ["en_GB", "it_IT"]
}
},
"email:faker?locale=en_GB,it_IT": "email"
}
The record generated for this spec will look something like:
{
"name": "Anita Bosio",
"email": "ocugia@example.net"
}
Providers
To make use of other faker module providers, you will need to add the include
config option:
{
"make_model": {
"type": "faker",
"data": "vehicle_make_model",
"config": {
"include": "faker_vehicle"
}
},
"cat": {
"type": "faker",
"data": "vehicle_category",
"config": {
"include": "faker_vehicle"
}
},
"year:faker?include=faker_vehicle": "vehicle_year"
}
The record generated for this spec will look something like:
{
"make_model": "Mercury Grand Marquis",
"cat": "Hatchback",
"year": "2014"
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for datacraft_faker-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2efd80d077554f6ce4c9be74822a19e45ef8a25c3b82dde8a99b7e07a6123a24 |
|
MD5 | 74ae7eeef60673c57f7e478487fac70e |
|
BLAKE2b-256 | da6723e060bc9eea1b4158fc018d6f0503b2e84c07dd9514cd2d86cd90d1fab1 |