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.orm.exc import MultipleResultsFound
from sqlalchemy import (Column, String, Integer, ForeignKey)
from sqlalchemy.orm import relationship
from sqlalchemy.sql.schema import UniqueConstraint
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'})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for SqlAlchemy_Tools-0.0.1b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b4b9906673b8394c08db260917724b6c31513bda67f39629a95a4dac46fb2bd |
|
MD5 | 59ec49927d7779b9d931b6919ce39352 |
|
BLAKE2b-256 | 76d98d02c102061c2788ed69787eb75b103e2645d4bc1f10a9ec6346382b8f7a |