This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Automatically generates pretty repr of a SQLAlchemy model.

Project Description

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=datetime.datetime(2016, 6, 1, 0, 0)>

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=datetime.datetime(2016, 6, 1, 0, 0),
    modified=datetime.datetime(2016, 6, 1, 0, 0)>
Release History

Release History

This version
History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
sqlalchemy-repr-0.0.1.linux-x86_64.tar.gz (4.1 kB) Copy SHA256 Checksum SHA256 any Dumb Binary Jun 16, 2016
sqlalchemy_repr-0.0.1-py3.5.egg (4.6 kB) Copy SHA256 Checksum SHA256 3.5 Egg Jun 16, 2016
sqlalchemy-repr-0.0.1.tar.gz (4.5 kB) Copy SHA256 Checksum SHA256 Source Jun 16, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting