Registry / type-stubs / types-sqlalchemy

types-sqlalchemy

JSON →
library1.4.53.38pypypiunverified

types-sqlalchemy is a PEP 561 type stub package designed to provide static type checking for the SQLAlchemy library. It enables type checkers such as MyPy, Pyright, Pytype, and PyCharm to analyze code that uses SQLAlchemy, improving code quality and catching potential errors at development time. This package is part of the `typeshed` project and primarily supports SQLAlchemy 1.x, with SQLAlchemy 2.0+ integrating native type annotations. It is actively maintained as part of typeshed.

pip install types-sqlalchemy
INSTALL
IMPORT
SIG · TYPES-SQLALCHEMY
T
types-sqlalchemy
type-stubspythonv1.4.53.38
Install
1.6s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.53.38 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Column
from sqlalchemy_stubs import Column
from sqlalchemy-stubs import Column

This quickstart demonstrates a basic SQLAlchemy declarative model with type hints. When `types-sqlalchemy` is installed, a static type checker (like MyPy) can analyze this code to ensure type correctness for SQLAlchemy constructs (e.g., `Column`, `String`, `Mapped`). For SQLAlchemy 2.0+, native typing is available and recommended over external stubs.

from sqlalchemy import create_engine, Column, Integer, String from sqlalchemy.orm import declarative_base, sessionmaker from typing import Optional # types-sqlalchemy provides stubs that enable type checkers # to understand the types of SQLAlchemy objects like Column, String, etc. Base = declarative_base() class User(Base): __tablename__ = 'users' id: Mapped[int] = mapped_column(Integer, primary_key=True) name: Mapped[str] = mapped_column(String) email: Mapped[Optional[str]] = mapped_column(String, nullable=True) def __repr__(self) -> str: return f"<User(id={self.id}, name='{self.name}', email='{self.email}')>" # Example usage (runtime, type-checked by types-sqlalchemy) # In a real application, you would typically use an environment variable for the connection string DATABASE_URL = "sqlite:///:memory:" engine = create_engine(DATABASE_URL) Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() new_user = User(name='Alice', email='alice@example.com') session.add(new_user) session.commit() retrieved_user: Optional[User] = session.query(User).filter_by(name='Alice').first() if retrieved_user: print(retrieved_user) # type: ignore session.close()
Debug
Known issues
breakingSQLAlchemy versions 2.0 and newer include native type annotations. Using `types-sqlalchemy` alongside SQLAlchemy 2.0+ can lead to conflicts and incorrect type checking results. It is strongly recommended to uninstall `types-sqlalchemy` if you are using SQLAlchemy 2.0 or a newer version and rely on SQLAlchemy's built-in typing.
fix
Uninstall `types-sqlalchemy` using `pip uninstall types-sqlalchemy`. Consult SQLAlchemy's official documentation for 2.0+ native typing guidance.
affects: SQLAlchemy >= 2.0
gotchaThere are alternative SQLAlchemy stub packages, notably `sqlalchemy-stubs`. While `types-sqlalchemy` is part of the official `typeshed` project and is plugin-agnostic, `sqlalchemy-stubs` provides a MyPy plugin for potentially more precise type inference in some complex cases. Choose one based on your specific type-checking needs and tooling.
fix
Review the documentation for both `types-sqlalchemy` (part of typeshed) and `sqlalchemy-stubs` to decide which best fits your project's requirements, especially if using a MyPy plugin is beneficial. Avoid installing both simultaneously.
affects: All versions
gotchaContributions and fixes for `types-sqlalchemy` should be made directly to the `typeshed` repository on GitHub (`https://github.com/python/typeshed/tree/main/stubs/SQLAlchemy`), not to the `types-sqlalchemy` PyPI project directly.
fix
To report issues or contribute type fixes, open a pull request or issue against the relevant stub directory within the `typeshed` GitHub repository.
affects: All versions
Upgrade
Version history
1.4.53.38latest on PyPI · released May 1, 2023
Audit
Dependencies
SQLAlchemyrequiredThis package provides type stubs for SQLAlchemy; SQLAlchemy itself must be installed to use these stubs for type checking.
Agent activity
51 hits · last 30 days
node
45
Meta
2
OpenAI (training)
1
Resources
types-sqlalchemy — pip install types-sqlalchemy · libregistry