Examples¶
This directory contains ready-to-run examples demonstrating the key features of sqlatypemodel.
Quick Start¶
Install dependencies:
poetry install --all-extras
# OR
pip install pydantic attrs sqlalchemy aiosqlite orjson
Run any example:
python 01_pydantic_basic.py
Available Examples¶
01_pydantic_basic.py: Basic setup with Pydantic and SQLAlchemy.
02_lazy_loading.py: Demonstrates the performance boost of
LazyMutableMixin.03_dataclasses.py: Integration with standard Python dataclasses.
04_attrs.py: Integration with the
attrslibrary.05_async_sqlalchemy.py: Usage with SQLAlchemy’s
AsyncSession.06_nested_collections.py: Tracking deep mutations in lists/dicts.
07_pickle_celery.py: Serialization and task queue compatibility.
comparison_bench.py: Detailed benchmark script comparing Eager vs Lazy loading performance and memory usage.
Safety & Testing¶
All examples use SQLite in-memory databases (no external database setup required).
Examples are tested as part of the CI/CD pipeline. See .github/WORKFLOWS.md for details.
Run examples in tests:
poetry run pytest examples/ -v
Performance Benchmarks¶
Run the comparison benchmark locally:
python comparison_bench.py
This compares: - Lazy vs Eager loading speeds - Memory usage differences - Initialization performance - Real-world DB workflow performance