Skip to main content

A library for generating fake Pydantic models for testing and development purposes

Project description

Fauxdantic

A library for generating fake Pydantic models for testing and development purposes. Fauxdantic makes it easy to create realistic test data for your Pydantic models.

Installation

poetry add fauxdantic

Features

  • Generate fake data for any Pydantic model
  • Support for nested models
  • Support for common Python types:
    • Basic types (str, int, float, bool)
    • Optional types
    • Lists
    • Dicts
    • UUIDs
    • Datetimes
    • Enums
  • Customizable values through keyword arguments

Usage

Basic Usage

from pydantic import BaseModel
from fauxdantic import fake_model

class User(BaseModel):
    name: str
    age: int
    email: str
    is_active: bool

# Generate a fake user
fake_user = fake_model(User)
print(fake_user)
# Output: name='Smith' age=2045 email='smith@example.com' is_active=True

Nested Models

from pydantic import BaseModel
from fauxdantic import fake_model

class Address(BaseModel):
    street: str
    city: str
    zip_code: str

class User(BaseModel):
    name: str
    age: int
    address: Address

# Generate a fake user with nested address
fake_user = fake_model(User)
print(fake_user)
# Output: name='Smith' age=2045 address=Address(street='123 Main St', city='Anytown', zip_code='12345')

Optional Fields

from typing import Optional
from pydantic import BaseModel
from fauxdantic import fake_model

class User(BaseModel):
    name: str
    age: Optional[int]
    email: Optional[str]

# Generate a fake user with optional fields
fake_user = fake_model(User)
print(fake_user)
# Output: name='Smith' age=None email='smith@example.com'

Lists and Dicts

from typing import List, Dict
from pydantic import BaseModel
from fauxdantic import fake_model

class User(BaseModel):
    name: str
    tags: List[str]
    preferences: Dict[str, str]

# Generate a fake user with lists and dicts
fake_user = fake_model(User)
print(fake_user)
# Output: name='Smith' tags=['tag1', 'tag2'] preferences={'key1': 'value1', 'key2': 'value2'}

Custom Values

from pydantic import BaseModel
from fauxdantic import fake_model

class User(BaseModel):
    name: str
    age: int
    email: str

# Generate a fake user with custom values
fake_user = fake_model(User, name="John Doe", age=30)
print(fake_user)
# Output: name='John Doe' age=30 email='smith@example.com'

Enums

from enum import Enum
from pydantic import BaseModel
from fauxdantic import fake_model

class UserRole(str, Enum):
    ADMIN = "admin"
    USER = "user"
    GUEST = "guest"

class User(BaseModel):
    name: str
    role: UserRole

# Generate a fake user with enum
fake_user = fake_model(User)
print(fake_user)
# Output: name='Smith' role=<UserRole.ADMIN: 'admin'>

Development

# Install dependencies
poetry install

# Run tests
poetry run pytest

# Format code
poetry run black .
poetry run isort .

# Type checking
poetry run mypy .

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

fauxdantic-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fauxdantic-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file fauxdantic-0.1.0.tar.gz.

File metadata

  • Download URL: fauxdantic-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.3 Darwin/24.4.0

File hashes

Hashes for fauxdantic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89f998f359b23c1655abfc515f8149d2dbdcf1f9935678d020bb9b8363ad4ad0
MD5 ba5a201aae084d2186a9e68f9f863c60
BLAKE2b-256 f2ae0565e9dea0d828ee49328410540d08101fa5862243e2ec7afb722f983792

See more details on using hashes here.

File details

Details for the file fauxdantic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fauxdantic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.3 Darwin/24.4.0

File hashes

Hashes for fauxdantic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bffed521bf662d9cb21eeb2c61acf96ddbb97ba62d61028de60baa0e6e22843d
MD5 b2bbd721bfd1c3d7ac668ae094bd7ccf
BLAKE2b-256 226385363e07128a5ec6ff342ddbef134a3526774380be7737b5a132fbf3b527

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page