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 interfacesqlean/extensions.pyi- Extension management APIsqlean/py.typed- PEP 561 marker filetests/test_types.py- Runtime teststests/test_mypy.py- Type checking tests
Adding Type Hints
- Update the
.pyistub file - Add runtime test in
tests/test_types.py - Add type checking test in
tests/test_mypy.py - Run
pytest tests/,mypy tests/test_mypy.py, andty check
Code Style
- Follow PEP 484 for type hints
- Use
Optional[X]instead ofX | None(Python 3.9 compatibility) - Use
Literaltypes 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.2.tar.gz
(12.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlean_stubs-0.0.2.tar.gz.
File metadata
- Download URL: sqlean_stubs-0.0.2.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15b11416f0ea7357017cb33939c7b5a21df93a45f3ac419addfe27be5fb528b7
|
|
| MD5 |
d8761139dd6bf9a2c3e4078000b38fa1
|
|
| BLAKE2b-256 |
1b853a3c9c177d48dca70fc1689bb042e1b37b03a21f2480edd6dc4e2e36d79e
|
File details
Details for the file sqlean_stubs-0.0.2-py3-none-any.whl.
File metadata
- Download URL: sqlean_stubs-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf7956d82ec657332799f502f3e2b781ef658300ba4c6b0ef8f69bd5b26fff2a
|
|
| MD5 |
3418f4311561795812625a1b47c38ffd
|
|
| BLAKE2b-256 |
7a6765809d467710f054527c78a2726de058e81b12e31258ec91c3ea0232333d
|