All Projects → dropbox → Sqlalchemy Stubs

dropbox / Sqlalchemy Stubs

Licence: apache-2.0
Mypy plugin and stubs for SQLAlchemy

Programming Languages

python
139335 projects - #7 most used programming language
types
53 projects

Projects that are alternatives of or similar to Sqlalchemy Stubs

Records
SQL for Humans™
Stars: ✭ 6,761 (+1607.32%)
Mutual labels:  sql, sqlalchemy
Qb
The database toolkit for go
Stars: ✭ 524 (+32.32%)
Mutual labels:  sql, sqlalchemy
Eralchemy
Entity Relation Diagrams generation tool
Stars: ✭ 767 (+93.69%)
Mutual labels:  sql, sqlalchemy
Databook
A facebook for data
Stars: ✭ 26 (-93.43%)
Mutual labels:  sql, sqlalchemy
Alembic
A database migrations tool for SQLAlchemy.
Stars: ✭ 874 (+120.71%)
Mutual labels:  sql, sqlalchemy
Sqlservice
The missing SQLAlchemy ORM interface.
Stars: ✭ 159 (-59.85%)
Mutual labels:  sql, sqlalchemy
Sql to sqlalchemy
本教程是为了展现 sql 原始语句转换为 sqlalchemy 语句的各个实例。
Stars: ✭ 75 (-81.06%)
Mutual labels:  sql, sqlalchemy
Sqlalchemy
The Database Toolkit for Python
Stars: ✭ 4,637 (+1070.96%)
Mutual labels:  sql, sqlalchemy
Asyncpgsa
A wrapper around asyncpg for use with sqlalchemy
Stars: ✭ 371 (-6.31%)
Mutual labels:  sqlalchemy
Pg timetable
pg_timetable: Advanced scheduling for PostgreSQL
Stars: ✭ 382 (-3.54%)
Mutual labels:  sql
Kyuubi
Kyuubi is a unified multi-tenant JDBC interface for large-scale data processing and analytics, built on top of Apache Spark
Stars: ✭ 363 (-8.33%)
Mutual labels:  sql
Hive
Apache Hive
Stars: ✭ 4,031 (+917.93%)
Mutual labels:  sql
Lessql
LessQL: A lightweight and performant PHP ORM alternative
Stars: ✭ 384 (-3.03%)
Mutual labels:  sql
Hyrise
Hyrise is a research in-memory database.
Stars: ✭ 371 (-6.31%)
Mutual labels:  sql
Franchise
🍟 a notebook sql client. what you get when have a lot of sequels.
Stars: ✭ 3,823 (+865.4%)
Mutual labels:  sql
Metorikku
A simplified, lightweight ETL Framework based on Apache Spark
Stars: ✭ 361 (-8.84%)
Mutual labels:  sql
Packetq
A tool that provides a basic SQL-frontend to PCAP-files
Stars: ✭ 363 (-8.33%)
Mutual labels:  sql
Data Driven Web Apps With Flask
Course demo code and other hand-out materials for our data-driven web apps in Flask course
Stars: ✭ 388 (-2.02%)
Mutual labels:  sqlalchemy
Ignite
Apache Ignite
Stars: ✭ 4,027 (+916.92%)
Mutual labels:  sql
Sqlx
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.
Stars: ✭ 5,039 (+1172.47%)
Mutual labels:  sql
mypy logo

Mypy plugin and stubs for SQLAlchemy

Build Status Checked with mypy

This package contains type stubs and a mypy plugin to provide more precise static types and type inference for SQLAlchemy framework. SQLAlchemy uses some Python "magic" that makes having precise types for some code patterns problematic. This is why we need to accompany the stubs with mypy plugins. The final goal is to be able to get precise types for most common patterns. Currently, basic operations with models are supported. A simple example:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String

Base = declarative_base()

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

user = User(id=42, name=42)  # Error: Incompatible type for "name" of "User"
                             # (got "int", expected "Optional[str]")
user.id  # Inferred type is "int"
User.name  # Inferred type is "Column[Optional[str]]"

Some auto-generated attributes are added to models. Simple relationships are supported but require models to be imported:

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from models.address import Address

...

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    address = relationship('Address')  # OK, mypy understands string references.

The next step is to support precise types for table definitions (e.g. inferring Column[Optional[str]] for users.c.name, currently it is just Column[Any]), and precise types for results of queries made using query() and select().

Installation

Install latest published version as:

pip install -U sqlalchemy-stubs

Important: you need to enable the plugin in your mypy config file:

[mypy]
plugins = sqlmypy

To install the development version of the package:

git clone https://github.com/dropbox/sqlalchemy-stubs
cd sqlalchemy-stubs
pip install -U .

Development Setup

First, clone the repo and cd into it, like in Installation, then:

git submodule update --init --recursive
pip install -r dev-requirements.txt

Then, to run the tests, simply:

pytest

Development status

The package is currently in alpha stage. See issue tracker for bugs and missing features. If you want to contribute, a good place to start is help-wanted label.

Currently, some basic use cases like inferring model field types are supported. The long term goal is to be able to infer types for more complex situations like correctly inferring columns in most compound queries.

External contributions to the project should be subject to Dropbox Contributor License Agreement (CLA).


Copyright (c) 2018 Dropbox, Inc.

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