Generate SQLAlchemy models with fake data
Project description
SQLAlchemy Model Faker
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
Built Distribution
Hashes for sqlalchemy_model_faker-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c5f12a4cc1b957d33db6fa00d67f6fc1aec26b1fd5ed33451c0348eead27bb6 |
|
MD5 | 5ccb46707bb1a1f1c4faa5fb8aca29c7 |
|
BLAKE2b-256 | 030059b656bb7dd1ce911c6090902ab1866d68b9363cc3ca4168bddaae811ea0 |
Hashes for sqlalchemy_model_faker-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b39b747b2dfb07692e1565dd42d6acb846a2f650cb0e1945d29178288255478 |
|
MD5 | af60d33adf50f05477043ad05a223b11 |
|
BLAKE2b-256 | cdf7a361765e6df15b8174b5264a61046782f7dcfef98f20766928a5ea30facf |