sqlalchemy-repr
Automatically generates pretty repr of a SQLAlchemy model.
Install
pip install sqlalchemy-repr
Usage
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_repr import RepresentableBase
Base = declarative_base(cls=RepresentableBase)
Example
sqlalchemy_repr.RepresentableBase is mixin to add simple representation of columns.
>>> from datetime import datetime
>>> from sqlalchemy import Column, DateTime, Integer, Unicode, create_engine
>>> from sqlalchemy.ext.declarative import declarative_base
>>> from sqlalchemy.orm import sessionmaker
>>> from sqlalchemy_repr import RepresentableBase
>>> Base = declarative_base(cls=RepresentableBase)
>>> class User(Base):
... __tablename__ = 'users'
... id = Column(Integer, primary_key=True)
... name = Column(Unicode(255), nullable=False, unique=True)
... created = Column(DateTime, nullable=False)
>>> engine = create_engine('sqlite://')
>>> Base.metadata.create_all(engine)
>>> Session = sessionmaker(bind=engine)
>>> session = Session()
>>> user = User(name='spam', created=datetime(2016, 6, 1))
>>> session.add(user)
>>> session.commit()
>>> print(user)
<User id=1, name='spam', created='2016-06-01T00:00:00'>
sqlalchemy_repr.PrettyRepresentableBase brings pretty, indented multi-line representation.
>>> from sqlalchemy_repr import PrettyRepresentableBase
>>> Base = declarative_base(cls=PrettyRepresentableBase)
>>> class User(Base):
... __tablename__ = 'users'
... id = Column(Integer, primary_key=True)
... first_name = Column(Unicode(255), nullable=False, unique=True)
... last_name = Column(Unicode(255), nullable=False, unique=True)
... email = Column(Unicode(255), nullable=False)
... created = Column(DateTime, nullable=False)
... modified = Column(DateTime, nullable=False)
>>> engine = create_engine('sqlite://')
>>> Base.metadata.create_all(engine)
>>> Session = sessionmaker(bind=engine)
>>> session = Session()
>>> user = User(first_name='spam', last_name='ham', email='spam@example.com', created=datetime(2016, 6, 1), modified=datetime(2016, 6, 1))
>>> session.add(user)
>>> session.commit()
>>> print(user)
<User
id=1,
first_name='spam',
last_name='ham',
email='spam@example.com',
created='2016-06-01T00:00:00',
modified='2016-06-01T00:00:00'>
Metadata
Release files for sqlalchemy-repr 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sqlalchemy-repr-0.1.0.tar.gz | 4.8 kB | Without provenance | Details |
Release files / sqlalchemy-repr-0.1.0.tar.gz
| Download URL | sqlalchemy-repr-0.1.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eaf46d28479bd7416d33a184affa851aba9231e0de38123218fa6dfb59f1f2e8
|
|
BLAKE2b-256 checksum How to use checksums |
b3afcb5be4b8a221653eaf385ae0d1634db9774e78413ade5982dd1c0784c2a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.8
|
Security for sqlalchemy-repr 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.