Skip to main content

SQLAlchemy Model Builder

Project description

SQLAlchemy Model Builder

test publish codecov pypi

Features

  • Build SQLAlchemy model instance with random data
  • Save SQLAlchemy model instance with random data
  • Build relationships
  • Build minimal (with required fields) only

Installation

$ pip install sqlalchemy-model-builder

How to use

Deinfe the SQLAlchemy models:

from sqlalchemy import Integer, String, Text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class Address(Base):
    __tablename__ = "addresses"

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey("users.id"))
    user = relationship("User", back_populates="addresses")


class User(Base):
    __tablename__ = "users"

    addresses = relationship("Address", back_populates="user")
    bio = Column(Text)
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)

Save random model instance:

from sqlalchemy_model_builder import ModelBuilder

random_user = ModelBuilder(User).save(db)

Build random model without saving:

random_user = ModelBuilder(User).build()

Build minimal model instance:

minimal_random_user = ModelBuilder(User, minimal=True).build()

Build or save with specific values:

random_address = ModelBuilder(Address).build(user_id=1)

Supported Data Types

  • BigInteger
  • Boolean
  • Date
  • DateTime
  • Enum
  • Float
  • Integer
  • Interval
  • LargeBinary
  • MatchType (Todo)
  • Numeric
  • PickleType (Todo)
  • SchemaType (Todo)
  • SmallInteger
  • String
  • Text
  • Time
  • Unicode
  • UnicodeText

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_builder-0.3.0.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

sqlalchemy_model_builder-0.3.0-py3-none-any.whl (6.2 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