Skip to main content

SQLAlchemy Model Builder

Project description

SQLAlchemy Model Builder

test publish codecov pypi

Features

  • Build and Save SQLALchemy models with random data
  • Build relationships (Todo)
  • Build minimal (with required) fields only

How to use

Build SQLAlchemy model:

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

from sqlalchemy_model_builder import ModelBuilder

Base = declarative_base()


class User(Base):
    __tablename__ = "users"

    bio = Column(Text)
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)


random_user = ModelBuilder(User).build()  # This will not insert the User

minimal_random_user = ModelBuilder(User, minimal=True).build()  # Builds User with `id` and `name`

Save SQLAlchemy model:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.sqltypes import Integer, String

from sqlalchemy_model_builder import ModelBuilder

Base = declarative_base()

engine = create_engine("sqlite://", echo=True)


class User(Base):
    __tablename__ = "users"

    bio = Column(Text)
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)


Base.metadata.create_all(engine)

LocalSession = sessionmaker(bind=engine)

db = LocalSession()


random_user = ModelBuilder(User).save(db=db)  # Builds and Saves model using provided session

Supported Data Types

  • BigInteger
  • Boolean
  • Date
  • DateTime
  • Enum (Todo)
  • Float
  • Integer
  • Interval
  • LargeBinary (Todo)
  • MatchType (Todo)
  • Numeric (Todo)
  • 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.0.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file sqlalchemy-model-builder-0.0.3.tar.gz.

File metadata

  • Download URL: sqlalchemy-model-builder-0.0.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0a1 CPython/3.8.10 Linux/5.4.0-1047-azure

File hashes

Hashes for sqlalchemy-model-builder-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f1ec252e90726e8f3019bfa4e0cd395503f66a3d642633937149a682992f9dd0
MD5 806202b84a656689387a7275c5fb30fe
BLAKE2b-256 a4168a0ff74b96965104b8ba13ead988c535edf1f30fc16893488f41a71a2802

See more details on using hashes here.

File details

Details for the file sqlalchemy_model_builder-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_model_builder-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a8c7c2915fc4487910d30f75170e711ce7d20d17238543e23dbc7da589153e91
MD5 66ecfb7a78b930bf731f1eed4cabc666
BLAKE2b-256 b28995b0376659bc76bc11bc07787c021dcce4f988658b14c58213f51fa3f03c

See more details on using hashes here.

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