jpsca / Sqla Wrapper
Licence: apache-2.0
A friendly wrapper for SQLAlchemy
Stars: ✭ 111
Programming Languages
python
139335 projects - #7 most used programming language
Labels
Projects that are alternatives of or similar to Sqla Wrapper
Sqlservice
The missing SQLAlchemy ORM interface.
Stars: ✭ 159 (+43.24%)
Mutual labels: sqlalchemy, database
Python For Entrepreneurs Course Demos
Contains all the "handout" materials for Talk Python's Python for Entrepreneurs course. This includes notes and the final version of the website code.
Stars: ✭ 247 (+122.52%)
Mutual labels: sqlalchemy, database
Clickhouse Sqlalchemy
ClickHouse dialect for SQLAlchemy
Stars: ✭ 166 (+49.55%)
Mutual labels: sqlalchemy, database
Tornado Sqlalchemy
SQLAlchemy support for Tornado
Stars: ✭ 112 (+0.9%)
Mutual labels: sqlalchemy, database
Sandman2
Automatically generate a RESTful API service for your legacy database. No code required!
Stars: ✭ 1,765 (+1490.09%)
Mutual labels: sqlalchemy, database
Flask Base
A simple Flask boilerplate app with SQLAlchemy, Redis, User Authentication, and more.
Stars: ✭ 2,680 (+2314.41%)
Mutual labels: sqlalchemy, database
Openimu
Open Source Analytics & Visualisation Software for Inertial Measurement Units
Stars: ✭ 133 (+19.82%)
Mutual labels: sqlalchemy, database
Etlalchemy
Extract, Transform, Load: Any SQL Database in 4 lines of Code.
Stars: ✭ 460 (+314.41%)
Mutual labels: sqlalchemy, database
Architect
A set of tools which enhances ORMs written in Python with more features
Stars: ✭ 320 (+188.29%)
Mutual labels: sqlalchemy, database
Data Driven Web Apps With Pyramid And Sqlalchemy
Demos and handouts for Talk Python's Data-Driven Web Apps with Pyramid and SQLAlchemy course
Stars: ✭ 79 (-28.83%)
Mutual labels: sqlalchemy, database
Flask Boilerplate
Simple flask boilerplate with Postgres, Docker, and Heroku/Zeit now
Stars: ✭ 251 (+126.13%)
Mutual labels: sqlalchemy, database
Eralchemy
Entity Relation Diagrams generation tool
Stars: ✭ 767 (+590.99%)
Mutual labels: sqlalchemy, database
Oreilly reactive python for data
Resources for the O'Reilly online video "Reactive Python for Data"
Stars: ✭ 98 (-11.71%)
Mutual labels: sqlalchemy, database
Flask Graphene Sqlalchemy
⚗️Project template to build a GraphQL API in Python
Stars: ✭ 109 (-1.8%)
Mutual labels: sqlalchemy
Tableqa
AI Tool for querying natural language on tabular data.
Stars: ✭ 109 (-1.8%)
Mutual labels: database
Etcd
Distributed reliable key-value store for the most critical data of a distributed system
Stars: ✭ 38,238 (+34348.65%)
Mutual labels: database
Gungnir
A fully featured, data-driven database library for Clojure.
Stars: ✭ 110 (-0.9%)
Mutual labels: database
SQLA-wrapper
A friendly wrapper for SQLAlchemy.
Why?
SQLAlchemy is great, but can be difficult to set up. With SQLA-Wrapper you can quickly start like:
from sqla_wrapper import SQLAlchemy
db = SQLAlchemy('sqlite:///:memory:')
class User(db.Model):
__tablename__ "users"
id = db.Column(db.Integer, primary_key=True)
...
db.create_all()
todos = db.query(User.id, User.title).all()
instead of having to write something like:
# Who's going to remember all of this?
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, Column, Integer
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()
Model = declarative_base()
class User(Model):
__tablename__ "users"
id = Column(Integer, primary_key=True)
...
Model.metadata.create_all(engine)
session = Session()
todos = session.query(User).all()
Installation
Install the package using Pypi:
python -m pip install sqla-wrapper
Basic usage
from sqla_wrapper import SQLAlchemy
db = SQLAlchemy('sqlite:///:memory:')
class User(db.Model):
__tablename__ "users"
id = db.Column(db.Integer, primary_key=True)
...
db.create_all()
db.add(User(...))
db.commit()
todos = db.query(User).all()
Compared to SQLAlchemy
Compared to plain SQLAlchemy, you need to know that:
The SQLAlchemy
gives you access to the following things:
- All the functions and classes from
sqlalchemy
andsqlalchemy.orm
- All the functions from a preconfigured scoped session (called
_session
). - The
~SQLAlchemy.metadata
and~SQLAlchemy.engine
- The methods
SQLAlchemy.create_all
andSQLAlchemy.drop_all
to create and drop tables according to the models. - A
Model
baseclass that is a configured declarative base. This model has a few utility methods:
class Model(Object):
@classmethod
def exists(cls, **attrs):
"""Returns whether an object with these attributes exists."""
@classmethod
def create(cls, **attrs):
"""Create and persist a new record for the model."""
@classmethod
def create_or_first(cls, **attrs):
"""Tries to create a new record, and if it fails
because already exists, return the first it founds."""
@classmethod
def first(cls, **attrs):
"""Returns the first object found with these attributes."""
def save(self):
"""Saves the updated model to the current entity db and commits."""
def delete(self):
"""Removes the model from the current session and commits."""
This model class also generates a default repr for your models, based on their class names an primary keys.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].