Skip to main content

Generate SQLAlchemy models with fake data

Project description

SQLAlchemy Model Faker

rogervila/sqlalchemy_model_faker

Coverage Quality Gate Status Maintainability Rating

Generate SQLAlchemy models with fake data.

IMPORTANT: Documentation asumes previous knowledge on how to work with SQLAlchemy.

Install

pip install sqlalchemy_model_faker

Usage

The package expects a SQLAlchemy model that extends from declarative_base().

It reads the model columns and generates a fake value according with the column type.

Basic Usage

Let's create a Product model with a description and a price columns.

from sqlalchemy.ext.declarative import declarative_base

class Product(declarative_base()):
    __tablename__ = 'products'
    id = Column(Integer, primary_key=True, autoincrement=True)
    description = Column(Text)
    price = Column(Integer)

Use factory to create a fake Product model.

from sqlalchemy_model_faker import factory

product = factory(Product).make()

print(type(product.description)) # <class 'str'>
print(type(product.price)) # <class 'int'>

Use SQLAlchemy session to persist the product into the database.

Custom values

By passing a dict, you can force factory to use custom provided values.

Other column values will be set with fake data.

from sqlalchemy_model_faker import factory

product = factory(Product).make({'price': 288})

print(product.price) # 288

Ignoring columns

Columns might be ignored. Their generated value will be None.

Other column values will be set with fake data.

from sqlalchemy_model_faker import factory

product = factory(Product).make(ignored_columns=['price'])

print(product.price) # None

License

This project is open-sourced software licensed under the MIT 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

sqlalchemy_model_faker-0.0.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

sqlalchemy_model_faker-0.0.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

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