Skip to main content

sqlean-stubs

Type hints for sqlean.py - Python's sqlite3 + extensions.

Installation

pip install sqlean-stubs

or with uv:

uv add sqlean-stubs

Usage

Type hints enable IDE autocomplete and type checking for sqlean code:

from typing import Optional
import sqlean

def main_sqlean():
    print("Hello from try-sqlean-stubs!")
    conn: sqlean.Connection = sqlean.connect(":memory:")
    cursor: sqlean.Cursor = conn.cursor()

    # Create repos table
    cursor.execute("""
        CREATE TABLE repos (
            id INTEGER PRIMARY KEY,
            package_name TEXT NOT NULL,
            github_url TEXT NOT NULL
        )
    """)

    # Insert test data
    cursor.execute(
        "INSERT INTO repos (package_name, github_url) VALUES (?, ?)",
        ("sqlean.py", "https://github.com/nalgeon/sqlean.py")
    )
    cursor.execute(
        "INSERT INTO repos (package_name, github_url) VALUES (?, ?)",
        ("sqlean-stubs", "https://github.com/kracekumar/sqlean-stubs")
    )

    # Query the table
    cursor.execute("SELECT * FROM repos")

    # fetchone() returns Optional[Any]
    row: Optional[sqlean.Row] = cursor.fetchone()
    if row is not None:
        print(f"ID: {row[0]}, Package: {row[1]}, URL: {row[2]}")

    # User-defined functions
    def double(x: int) -> int:
        return x * 2

    conn.create_function("double", 1, double)
    conn.close()

if __name__ == "__main__":
    main_sqlean()

Benefits:

  • IDE autocomplete and navigation
  • Catch type errors before runtime with mypy or ty
  • Better code documentation and refactoring safety

Features

  • Complete type hints for Connection, Cursor, and Row objects
  • Support for custom factories and row factories
  • Type hints for user-defined functions and aggregates
  • Callbacks support (authorizer, progress handler, trace callback, busy handler)
  • Window function support
  • Extensions management API
  • Compatible with mypy, ty, pyright, and other type checkers

Requirements

  • Python 3.9 or later
  • pip, uv, or pipx for installation

Contributing

Development Setup

git clone https://github.com/nalgeon/sqlean-stubs.git
cd sqlean-stubs
uv sync

Running Tests

# Run all tests
uv run pytest tests/

# Linting
uv run ruff check .

# Type checking
uv run mypy tests/test_mypy.py
uv run ty check

# Test multiple Python versions (3.9-3.14)
uv run tox

Project Structure

  • sqlean/dbapi2.pyi - Main DB-API 2.0 interface
  • sqlean/extensions.pyi - Extension management API
  • sqlean/py.typed - PEP 561 marker file
  • tests/test_types.py - Runtime tests
  • tests/test_mypy.py - Type checking tests

Adding Type Hints

  1. Update the .pyi stub file
  2. Add runtime test in tests/test_types.py
  3. Add type checking test in tests/test_mypy.py
  4. Run pytest tests/, mypy tests/test_mypy.py, and ty check

Code Style

  • Follow PEP 484 for type hints
  • Use Optional[X] instead of X | None (Python 3.9 compatibility)
  • Use Literal types for constrained values
  • Include docstrings for complex types

Before Submitting

uv run ruff check .
uv run pytest tests/ -v
uv run mypy tests/test_mypy.py
uv run ty check

License

Zlib (same as sqlean.py)

Metadata

Release files for sqlean-stubs 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlean-stubs 0.0.8
File Size Uploaded
sqlean_stubs-0.0.8.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlean-stubs 0.0.8
File Interpreter ABI Platform
sqlean_stubs-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / sqlean_stubs-0.0.8.tar.gz

Download URL sqlean_stubs-0.0.8.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bde11905f15786a54ffb912454080bae2fdbfd334e596ec536cb678b4889429f
BLAKE2b-256 checksum
How to use checksums
f0855103f6bf704d74d6e77712e796fec7a13df5bd18d60ccfaaa4d4ae6d8686
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Release files / sqlean_stubs-0.0.8-py3-none-any.whl

Download URL sqlean_stubs-0.0.8-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d30cf9438fb992cea61abf498c61d03eac78a579e8d6f9b93d70c07ba745f54c
BLAKE2b-256 checksum
How to use checksums
11caa338c2138dae91727eebc3c8f4ca43c866a2a667147742b8b5bd3da35e51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.3

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page