Skip to main content

Type hints for sqlean.py (sqlite3 + extensions)

Project description

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:

import sqlean

conn: sqlean.Connection = sqlean.connect(":memory:")
cursor = conn.cursor()

# Type hints work with parameters
cursor.execute("SELECT * FROM users WHERE id = ?", (1,))

# fetchone() returns Optional[Any]
row = cursor.fetchone()
if row is not None:
    print(row[0])  # Type-safe indexing

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

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

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlean_stubs-0.0.5.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlean_stubs-0.0.5-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file sqlean_stubs-0.0.5.tar.gz.

File metadata

  • Download URL: sqlean_stubs-0.0.5.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for sqlean_stubs-0.0.5.tar.gz
Algorithm Hash digest
SHA256 b12cfa1d207aa05ba9a5a390575f688cee60455a116a6437b24a6ac407c5b011
MD5 ec37b0a317a123493c54bd27090ab88f
BLAKE2b-256 0b20b6ba3ceb203e34b96e957e3cec461f4a012d55f046edac9de61602c5e545

See more details on using hashes here.

File details

Details for the file sqlean_stubs-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlean_stubs-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a66c116f0c3c7b2447235bb8c55e07a084732895b1d00ea6b79e844bd7373e0f
MD5 8c5f495983895b9b516ad702d6ba3323
BLAKE2b-256 d60f566fa4047fd7ffe478625ed4f3bcf0b220248b15df9203e6aa21d0ec8011

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page