Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sqlalchemy-repr

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqlalchemy-repr

Automatically generates pretty repr of a SQLAlchemy model.

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

sqlalchemy-repr

.. image:: https://travis-ci.org/manicmaniac/sqlalchemy-repr.svg?branch=master :target: https://travis-ci.org/manicmaniac/sqlalchemy-repr

Automatically generates pretty repr of a SQLAlchemy model.

Install

.. code:: sh

pip install sqlalchemy-repr

Usage

.. code:: python

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.

.. code:: python

>>> 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.

.. code:: python

>>> 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'>

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc