Lightweight test data generation with realistic fake values.
Project description
philiprehberger-data-factory
Lightweight test data generation with realistic fake values.
Installation
pip install philiprehberger-data-factory
Usage
Generate fake values
from philiprehberger_data_factory import fake
fake.name() # "Alice Johnson"
fake.email() # "bob.smith@example.com"
fake.integer() # 472
fake.boolean() # True
fake.text() # "alpha bravo charlie delta echo"
fake.date() # "2023-07-14"
fake.uuid() # "a3b2c1d4-..."
fake.phone() # "+1-555-123-4567"
fake.address() # "742 Oak Street, Springfield"
Factory
Define a schema and generate records in bulk:
from philiprehberger_data_factory import Factory
user_factory = Factory({
"name": "name",
"email": "email",
"age": "integer",
"bio": "text",
"joined": "date",
"id": "uuid",
"phone": "phone",
"address": "address",
})
user = user_factory.build()
# {'name': 'Grace Wilson', 'email': 'henry.moore@mail.com', ...}
users = user_factory.build_batch(100)
# [{'name': ..., 'email': ..., ...}, ...]
Weighted choices
from philiprehberger_data_factory import fake
tier = fake.weighted_choice({"gold": 0.1, "silver": 0.3, "bronze": 0.6})
Custom providers
Pass a callable instead of a provider string:
from philiprehberger_data_factory import fake, Factory
factory = Factory({
"name": "name",
"role": lambda: fake.choice(["admin", "editor", "viewer"]),
})
Reproducible output
from philiprehberger_data_factory import fake
fake.seed(42)
fake.name() # always the same name for seed 42
API
| Method / Function | Description |
|---|---|
fake.name() |
Random full name |
fake.email() |
Random email address |
fake.integer(min, max) |
Random integer (default 0-1000) |
fake.decimal(min, max, precision) |
Random float (default 0-1000, 2 decimals) |
fake.boolean() |
Random True or False |
fake.choice(items) |
Random element from a list |
fake.text(words) |
Random words (default 5) |
fake.date(start, end) |
Random ISO date string |
fake.uuid() |
Random UUID4 string |
fake.phone() |
Random phone number in +1-XXX-XXX-XXXX format |
fake.address() |
Random street address with city |
fake.weighted_choice(options) |
Weighted random selection from a dict of options to weights |
fake.seed(n) |
Set random seed for reproducibility |
Factory(schema) |
Create a factory from a schema dict |
factory.build() |
Generate one record |
factory.build_batch(n) |
Generate n records |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this package useful, consider starring the repository.
License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_data_factory-0.2.0.tar.gz.
File metadata
- Download URL: philiprehberger_data_factory-0.2.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88680de61c38e2d98f0c3e832c401083fcae1c44d1e791aa71d6a92b70e82d5e
|
|
| MD5 |
2905939fc0dc08ff6cf611bd8715c7c5
|
|
| BLAKE2b-256 |
6a5d21e8d040cf6158077a44dd479b49451b14a843faacf0b7471ab37cea8629
|
File details
Details for the file philiprehberger_data_factory-0.2.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_data_factory-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3661d6e5232a4c80fb491f25c120c89ab75692f5db5c85dcb8161dce0cea9420
|
|
| MD5 |
2baf29ff16ddaac6854fe59eaa5863d2
|
|
| BLAKE2b-256 |
3211dacc83e457593e05f3d696fd629176f2bc4b4ec32f310b52ffa6ebbb9202
|