Skip to main content

Wrapper to make using SqlAlchemy easier, thread safe, helper methods etc.

Project description

SqlAlchemy-Tools

SqlAlchemy_Tools is a tool that provides similar functionality to Flask_SqlAlchemy without being dependant on Flask.

Installation

Install SqlAlchemy-Tools with pip:

pip install sqlalchemy-tools

Features

  • Thread safe by using scoped_session
  • Integration with Pandas to allow quick dataframe insertion and retriving queries as dataframes
  • GetOrCreate functionality
  • Checking if an object is valid
  • Other general helper methods for creating/getting information

Example

from sqlalchemy import (Column, String, Integer, ForeignKey)

from sqlalchemy_tools import Database

db = Database('sqlite:///tmp.db')


class User(db.Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    fullname = Column(String)
    nickname = Column(String)


db.create_all_metadata()    # only required if not using alembic or using a database in memory
# db.register_models([User, Address])   # optional to allow for single imports, allows models to be accessed as `db.User`

u1 = User(name='Dave', fullname='Dave Smith', nickname='Davo')
u2 = User(name='Dave', fullname='Dave Owen', nickname='Dav Machine')
db.save([u1, u2])

u3 = db.get_or_create(User, {'name': 'Simon'})
User.query.all()

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_Tools-0.0.1b1.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

SqlAlchemy_Tools-0.0.1b1-py3-none-any.whl (7.1 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