data-retrieval-module 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data_retrieval_module-1.0.0/CHANGELOG.md +73 -0
- data_retrieval_module-1.0.0/LICENSE +21 -0
- data_retrieval_module-1.0.0/MANIFEST.in +36 -0
- data_retrieval_module-1.0.0/Makefile +65 -0
- data_retrieval_module-1.0.0/PKG-INFO +350 -0
- data_retrieval_module-1.0.0/README.md +288 -0
- data_retrieval_module-1.0.0/data_retrieval/__init__.py +61 -0
- data_retrieval_module-1.0.0/data_retrieval/model/__init__.py +11 -0
- data_retrieval_module-1.0.0/data_retrieval/model/data_module.py +150 -0
- data_retrieval_module-1.0.0/data_retrieval/model/data_provider.py +313 -0
- data_retrieval_module-1.0.0/data_retrieval/model/exceptions.py +38 -0
- data_retrieval_module-1.0.0/data_retrieval/py.typed +2 -0
- data_retrieval_module-1.0.0/data_retrieval_module.egg-info/PKG-INFO +350 -0
- data_retrieval_module-1.0.0/data_retrieval_module.egg-info/SOURCES.txt +21 -0
- data_retrieval_module-1.0.0/data_retrieval_module.egg-info/dependency_links.txt +1 -0
- data_retrieval_module-1.0.0/data_retrieval_module.egg-info/requires.txt +37 -0
- data_retrieval_module-1.0.0/data_retrieval_module.egg-info/top_level.txt +1 -0
- data_retrieval_module-1.0.0/pyproject.toml +174 -0
- data_retrieval_module-1.0.0/requirements-test.txt +35 -0
- data_retrieval_module-1.0.0/setup.cfg +4 -0
- data_retrieval_module-1.0.0/setup.py +8 -0
- data_retrieval_module-1.0.0/tests/__init__.py +1 -0
- data_retrieval_module-1.0.0/tests/test_basic.py +46 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2026-01-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of Data Retrieval Module
|
|
12
|
+
- Synchronous `DataProvider` abstract base class
|
|
13
|
+
- Asynchronous `AsyncDataProvider` abstract base class
|
|
14
|
+
- Standardized `QueryResult` data container
|
|
15
|
+
- Connection management with context managers
|
|
16
|
+
- Built-in retry logic with configurable parameters
|
|
17
|
+
- Hook methods for validation and transformation
|
|
18
|
+
- Comprehensive exception hierarchy
|
|
19
|
+
- Full type hints and generic support
|
|
20
|
+
- Comprehensive unit test suite (41 tests)
|
|
21
|
+
- PyPI package configuration
|
|
22
|
+
- Development tools configuration (black, isort, mypy, pytest)
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
- **Dual API Support**: Both sync and async interfaces
|
|
26
|
+
- **Connection Management**: Automatic connection handling
|
|
27
|
+
- **Retry Logic**: Configurable retry mechanisms
|
|
28
|
+
- **Type Safety**: Full type annotations
|
|
29
|
+
- **Error Handling**: Specific exception types
|
|
30
|
+
- **Testing**: Complete test coverage
|
|
31
|
+
- **Documentation**: Comprehensive README and API docs
|
|
32
|
+
|
|
33
|
+
### Documentation
|
|
34
|
+
- Complete README with usage examples
|
|
35
|
+
- API documentation for all classes
|
|
36
|
+
- Development setup instructions
|
|
37
|
+
- Contributing guidelines
|
|
38
|
+
|
|
39
|
+
### Development
|
|
40
|
+
- Setuptools and pyproject.toml configuration
|
|
41
|
+
- Pre-commit hooks configuration
|
|
42
|
+
- CI/CD ready setup
|
|
43
|
+
- Package publishing configuration
|
|
44
|
+
|
|
45
|
+
## [Unreleased]
|
|
46
|
+
|
|
47
|
+
### Planned
|
|
48
|
+
- Additional data source implementations
|
|
49
|
+
- Performance benchmarks
|
|
50
|
+
- Advanced caching mechanisms
|
|
51
|
+
- Metrics and monitoring support
|
|
52
|
+
- Integration with popular ORMs
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Version History
|
|
57
|
+
|
|
58
|
+
### v1.0.0-alpha (2025-11-13)
|
|
59
|
+
- Initial concept and design
|
|
60
|
+
- Basic abstract classes
|
|
61
|
+
- Core functionality implementation
|
|
62
|
+
|
|
63
|
+
### v1.0.0-beta (2025-12-01)
|
|
64
|
+
- Added async support
|
|
65
|
+
- Improved error handling
|
|
66
|
+
- Enhanced testing coverage
|
|
67
|
+
- Documentation improvements
|
|
68
|
+
|
|
69
|
+
### v1.0.0 (2026-01-14)
|
|
70
|
+
- Production-ready release
|
|
71
|
+
- Complete test suite
|
|
72
|
+
- PyPI publishing configuration
|
|
73
|
+
- Final documentation
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Abigail Williams
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Include additional files in the distribution
|
|
2
|
+
|
|
3
|
+
# Documentation
|
|
4
|
+
include README.md
|
|
5
|
+
include CHANGELOG.md
|
|
6
|
+
include LICENSE
|
|
7
|
+
|
|
8
|
+
# Configuration files
|
|
9
|
+
include pyproject.toml
|
|
10
|
+
include setup.py
|
|
11
|
+
|
|
12
|
+
# Type information
|
|
13
|
+
include data_retrieval/py.typed
|
|
14
|
+
|
|
15
|
+
# Test files (optional - for source distributions)
|
|
16
|
+
recursive-include tests *.py
|
|
17
|
+
include pytest.ini
|
|
18
|
+
include requirements-test.txt
|
|
19
|
+
|
|
20
|
+
# Development files (optional)
|
|
21
|
+
include Makefile
|
|
22
|
+
recursive-include .benchmarks *.py
|
|
23
|
+
|
|
24
|
+
# Exclude unnecessary files
|
|
25
|
+
global-exclude *.pyc
|
|
26
|
+
global-exclude *.pyo
|
|
27
|
+
global-exclude *.pyd
|
|
28
|
+
global-exclude __pycache__
|
|
29
|
+
global-exclude .git*
|
|
30
|
+
global-exclude .pytest_cache
|
|
31
|
+
global-exclude .mypy_cache
|
|
32
|
+
global-exclude .coverage
|
|
33
|
+
global-exclude htmlcov
|
|
34
|
+
global-exclude *.egg-info
|
|
35
|
+
global-exclude build
|
|
36
|
+
global-exclude dist
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Makefile for Data Retrieval Module Testing
|
|
2
|
+
# Author: AbigailWilliams1692
|
|
3
|
+
# Created: 2025-11-13
|
|
4
|
+
# Updated: 2025-01-14
|
|
5
|
+
|
|
6
|
+
.PHONY: help test test-unit test-integration test-async test-coverage test-all clean install format lint
|
|
7
|
+
|
|
8
|
+
# Default target
|
|
9
|
+
help:
|
|
10
|
+
@echo "Available commands:"
|
|
11
|
+
@echo " help - Show this help message"
|
|
12
|
+
@echo " install - Install test dependencies"
|
|
13
|
+
@echo " test - Run all tests"
|
|
14
|
+
@echo " test-unit - Run unit tests only"
|
|
15
|
+
@echo " test-integration - Run integration tests only"
|
|
16
|
+
@echo " test-async - Run async tests only"
|
|
17
|
+
@echo " test-coverage - Run tests with coverage"
|
|
18
|
+
@echo " test-all - Run all test suites with coverage"
|
|
19
|
+
@echo " format - Format code with black and isort"
|
|
20
|
+
@echo " lint - Run linting with flake8 and mypy"
|
|
21
|
+
@echo " clean - Clean test artifacts"
|
|
22
|
+
|
|
23
|
+
# Installation
|
|
24
|
+
install:
|
|
25
|
+
pip install -r requirements-test.txt
|
|
26
|
+
|
|
27
|
+
# Testing
|
|
28
|
+
test:
|
|
29
|
+
pytest tests/ -v
|
|
30
|
+
|
|
31
|
+
test-unit:
|
|
32
|
+
pytest tests/ -v -m "unit"
|
|
33
|
+
|
|
34
|
+
test-integration:
|
|
35
|
+
pytest tests/ -v -m "integration"
|
|
36
|
+
|
|
37
|
+
test-async:
|
|
38
|
+
pytest tests/ -v -m "async_test"
|
|
39
|
+
|
|
40
|
+
test-coverage:
|
|
41
|
+
pytest tests/ --cov=data_retrieval --cov-report=html --cov-report=term
|
|
42
|
+
|
|
43
|
+
test-all:
|
|
44
|
+
pytest tests/ --cov=data_retrieval --cov-report=html --cov-report=term --cov-report=xml
|
|
45
|
+
|
|
46
|
+
# Code quality
|
|
47
|
+
format:
|
|
48
|
+
black tests/ data_retrieval/
|
|
49
|
+
isort tests/ data_retrieval/
|
|
50
|
+
|
|
51
|
+
lint:
|
|
52
|
+
flake8 tests/ data_retrieval/
|
|
53
|
+
mypy data_retrieval/
|
|
54
|
+
|
|
55
|
+
# Cleanup
|
|
56
|
+
clean:
|
|
57
|
+
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
58
|
+
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
|
|
59
|
+
find . -type f -name "*.pyc" -delete
|
|
60
|
+
rm -rf .coverage htmlcov/ pytest.xml .pytest_cache/ .mypy_cache/
|
|
61
|
+
|
|
62
|
+
# Development helpers
|
|
63
|
+
dev-test: format lint test
|
|
64
|
+
|
|
65
|
+
ci-test: install test-all
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: data-retrieval-module
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A standardized interface for data providers with sync and async support
|
|
5
|
+
Author-email: AbigailWilliams1692 <abigail.williams@example.com>
|
|
6
|
+
Maintainer-email: AbigailWilliams1692 <abigail.williams@example.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/AbigailWilliams1692/data-retrieval-module
|
|
9
|
+
Project-URL: Documentation, https://github.com/AbigailWilliams1692/data-retrieval-module/wiki
|
|
10
|
+
Project-URL: Repository, https://github.com/AbigailWilliams1692/data-retrieval-module
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/AbigailWilliams1692/data-retrieval-module/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/AbigailWilliams1692/data-retrieval-module/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: data,retrieval,provider,async,sync,database,api
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: Database
|
|
25
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: typing-extensions>=4.0.0; python_version < "3.10"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
40
|
+
Provides-Extra: async
|
|
41
|
+
Requires-Dist: aiohttp>=3.8.0; extra == "async"
|
|
42
|
+
Requires-Dist: aiosqlite>=0.19.0; extra == "async"
|
|
43
|
+
Requires-Dist: asyncpg>=0.28.0; extra == "async"
|
|
44
|
+
Provides-Extra: database
|
|
45
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "database"
|
|
46
|
+
Requires-Dist: PyMySQL>=1.0.0; extra == "database"
|
|
47
|
+
Provides-Extra: all
|
|
48
|
+
Requires-Dist: pytest>=7.0.0; extra == "all"
|
|
49
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "all"
|
|
50
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "all"
|
|
51
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "all"
|
|
52
|
+
Requires-Dist: black>=23.0.0; extra == "all"
|
|
53
|
+
Requires-Dist: flake8>=6.0.0; extra == "all"
|
|
54
|
+
Requires-Dist: mypy>=1.0.0; extra == "all"
|
|
55
|
+
Requires-Dist: isort>=5.12.0; extra == "all"
|
|
56
|
+
Requires-Dist: aiohttp>=3.8.0; extra == "all"
|
|
57
|
+
Requires-Dist: aiosqlite>=0.19.0; extra == "all"
|
|
58
|
+
Requires-Dist: asyncpg>=0.28.0; extra == "all"
|
|
59
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
60
|
+
Requires-Dist: PyMySQL>=1.0.0; extra == "all"
|
|
61
|
+
Dynamic: license-file
|
|
62
|
+
|
|
63
|
+
# Data Retrieval Module
|
|
64
|
+
|
|
65
|
+
A standardized interface for data providers with both synchronous and asynchronous support. This module provides abstract base classes that enable consistent data retrieval patterns across different data sources (APIs, databases, files, etc.).
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
- 🔄 **Dual API Support**: Both sync and async interfaces
|
|
70
|
+
- 🏗️ **Abstract Base Classes**: Standardized patterns for data providers
|
|
71
|
+
- 🔌 **Connection Management**: Built-in connection handling with context managers
|
|
72
|
+
- 🔄 **Retry Logic**: Automatic retry with configurable parameters
|
|
73
|
+
- 📊 **Pagination Support**: Standardized pagination with QueryResult
|
|
74
|
+
- 🎣 **Hook Methods**: Customizable validation and transformation
|
|
75
|
+
- 🧪 **Type Safety**: Full type hints and generic support
|
|
76
|
+
- ✅ **Well Tested**: Comprehensive unit test coverage
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
### Basic Installation
|
|
81
|
+
```bash
|
|
82
|
+
pip install data-retrieval-module
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### With Async Support
|
|
86
|
+
```bash
|
|
87
|
+
pip install data-retrieval-module[async]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Development Installation
|
|
91
|
+
```bash
|
|
92
|
+
pip install data-retrieval-module[dev]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### All Features
|
|
96
|
+
```bash
|
|
97
|
+
pip install data-retrieval-module[all]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Quick Start
|
|
101
|
+
|
|
102
|
+
### Synchronous Data Provider
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from data_retrieval import DataProvider, QueryResult
|
|
106
|
+
from data_retrieval.model import ProviderStatus
|
|
107
|
+
|
|
108
|
+
class UserProvider(DataProvider[User]):
|
|
109
|
+
def _connect(self) -> None:
|
|
110
|
+
self._db = Database.connect(...)
|
|
111
|
+
|
|
112
|
+
def _disconnect(self) -> None:
|
|
113
|
+
self._db.close()
|
|
114
|
+
|
|
115
|
+
def fetch(self, *args, **kwargs) -> QueryResult[User]:
|
|
116
|
+
filters = kwargs.get("filters", {})
|
|
117
|
+
users = self._db.users.find(filters)
|
|
118
|
+
return QueryResult(
|
|
119
|
+
data=users,
|
|
120
|
+
total_count=len(users),
|
|
121
|
+
metadata={"source": "database"}
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Usage
|
|
125
|
+
provider = UserProvider()
|
|
126
|
+
with provider.connection(host="localhost", port=5432):
|
|
127
|
+
result = provider.fetch(filters={"active": True})
|
|
128
|
+
for user in result.data:
|
|
129
|
+
print(user.name)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Asynchronous Data Provider
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from data_retrieval import AsyncDataProvider
|
|
136
|
+
|
|
137
|
+
class AsyncUserProvider(AsyncDataProvider[User]):
|
|
138
|
+
async def _connect(self) -> None:
|
|
139
|
+
self._db = await Database.connect(...)
|
|
140
|
+
|
|
141
|
+
async def _disconnect(self) -> None:
|
|
142
|
+
await self._db.close()
|
|
143
|
+
|
|
144
|
+
async def fetch(self, *args, **kwargs) -> QueryResult[User]:
|
|
145
|
+
filters = kwargs.get("filters", {})
|
|
146
|
+
users = await self._db.users.find(filters)
|
|
147
|
+
return QueryResult(
|
|
148
|
+
data=users,
|
|
149
|
+
total_count=len(users),
|
|
150
|
+
metadata={"source": "database"}
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Usage
|
|
154
|
+
async def main():
|
|
155
|
+
provider = AsyncUserProvider()
|
|
156
|
+
async with provider.async_connection(host="localhost", port=5432) as p:
|
|
157
|
+
result = await p.fetch(filters={"active": True})
|
|
158
|
+
for user in result.data:
|
|
159
|
+
print(user.name)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Core Classes
|
|
163
|
+
|
|
164
|
+
### DataProvider (Synchronous)
|
|
165
|
+
|
|
166
|
+
Abstract base class for synchronous data providers.
|
|
167
|
+
|
|
168
|
+
**Key Methods:**
|
|
169
|
+
- `connect(**config)` - Establish connection
|
|
170
|
+
- `disconnect()` - Close connection
|
|
171
|
+
- `fetch(*args, **kwargs)` - Retrieve data
|
|
172
|
+
- `fetch_or_raise(*args, **kwargs)` - Fetch with error handling
|
|
173
|
+
- `with_retry(operation, max_retries, retry_delay)` - Retry logic
|
|
174
|
+
|
|
175
|
+
**Hook Methods:**
|
|
176
|
+
- `validate(data)` - Validate data
|
|
177
|
+
- `transform(data)` - Transform data
|
|
178
|
+
- `health_check()` - Health status
|
|
179
|
+
|
|
180
|
+
### AsyncDataProvider (Asynchronous)
|
|
181
|
+
|
|
182
|
+
Abstract base class for asynchronous data providers.
|
|
183
|
+
|
|
184
|
+
**Key Methods:**
|
|
185
|
+
- `async connect(**config)` - Establish connection
|
|
186
|
+
- `async disconnect()` - Close connection
|
|
187
|
+
- `async fetch(*args, **kwargs)` - Retrieve data
|
|
188
|
+
- `async fetch_or_raise(*args, **kwargs)` - Fetch with error handling
|
|
189
|
+
- `async with_retry(operation, max_retries, retry_delay)` - Retry logic
|
|
190
|
+
|
|
191
|
+
### QueryResult
|
|
192
|
+
|
|
193
|
+
Standardized container for query results.
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
@dataclass
|
|
197
|
+
class QueryResult[T]:
|
|
198
|
+
data: List[T]
|
|
199
|
+
total_count: int
|
|
200
|
+
metadata: Dict[str, Any]
|
|
201
|
+
|
|
202
|
+
def is_empty(self) -> bool:
|
|
203
|
+
return self.total_count == 0
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Advanced Usage
|
|
207
|
+
|
|
208
|
+
### Custom Validation
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
class ValidatedProvider(DataProvider[User]):
|
|
212
|
+
def validate(self, data: User) -> bool:
|
|
213
|
+
# Custom validation logic
|
|
214
|
+
return data.email and "@" in data.email
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Data Transformation
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
class TransformingProvider(DataProvider[User]):
|
|
221
|
+
def transform(self, data: dict) -> User:
|
|
222
|
+
# Convert raw data to User object
|
|
223
|
+
return User(**data)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Retry Logic
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
provider = MyProvider()
|
|
230
|
+
|
|
231
|
+
# Retry with custom parameters
|
|
232
|
+
result = provider.with_retry(
|
|
233
|
+
operation=lambda: provider.fetch(filters={"id": "123"}),
|
|
234
|
+
max_retries=5,
|
|
235
|
+
retry_delay=2.0,
|
|
236
|
+
parameters={}
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Context Managers
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
# Automatic connection management
|
|
244
|
+
with provider.connection(host="localhost") as p:
|
|
245
|
+
data = p.fetch()
|
|
246
|
+
|
|
247
|
+
# Async version
|
|
248
|
+
async with provider.async_connection(host="localhost") as p:
|
|
249
|
+
data = await p.fetch()
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Error Handling
|
|
253
|
+
|
|
254
|
+
The module provides specific exception types:
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
from data_retrieval.model.exceptions import (
|
|
258
|
+
DataProviderError,
|
|
259
|
+
ConnectionError,
|
|
260
|
+
QueryError,
|
|
261
|
+
ValidationError
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
try:
|
|
265
|
+
result = provider.fetch(filters={"invalid": "field"})
|
|
266
|
+
except ConnectionError as e:
|
|
267
|
+
print(f"Connection failed: {e}")
|
|
268
|
+
except QueryError as e:
|
|
269
|
+
print(f"Query failed: {e}")
|
|
270
|
+
except DataProviderError as e:
|
|
271
|
+
print(f"General error: {e}")
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Development
|
|
275
|
+
|
|
276
|
+
### Setup Development Environment
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# Clone repository
|
|
280
|
+
git clone https://github.com/AbigailWilliams1692/data-retrieval-module.git
|
|
281
|
+
cd data-retrieval-module
|
|
282
|
+
|
|
283
|
+
# Create virtual environment
|
|
284
|
+
python -m venv venv
|
|
285
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
286
|
+
|
|
287
|
+
# Install development dependencies
|
|
288
|
+
pip install -e .[dev]
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Running Tests
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Run all tests
|
|
295
|
+
pytest
|
|
296
|
+
|
|
297
|
+
# Run with coverage
|
|
298
|
+
pytest --cov=data_retrieval --cov-report=html
|
|
299
|
+
|
|
300
|
+
# Run specific test file
|
|
301
|
+
pytest tests/test_data_provider.py
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Code Quality
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
# Format code
|
|
308
|
+
black data_retrieval/ tests/
|
|
309
|
+
|
|
310
|
+
# Sort imports
|
|
311
|
+
isort data_retrieval/ tests/
|
|
312
|
+
|
|
313
|
+
# Type checking
|
|
314
|
+
mypy data_retrieval/
|
|
315
|
+
|
|
316
|
+
# Linting
|
|
317
|
+
flake8 data_retrieval/ tests/
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Contributing
|
|
321
|
+
|
|
322
|
+
1. Fork the repository
|
|
323
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
324
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
325
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
326
|
+
5. Open a Pull Request
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
331
|
+
|
|
332
|
+
## Changelog
|
|
333
|
+
|
|
334
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of changes and version history.
|
|
335
|
+
|
|
336
|
+
## Support
|
|
337
|
+
|
|
338
|
+
- 📖 [Documentation](https://github.com/AbigailWilliams1692/data-retrieval-module/wiki)
|
|
339
|
+
- 🐛 [Bug Reports](https://github.com/AbigailWilliams1692/data-retrieval-module/issues)
|
|
340
|
+
- 💬 [Discussions](https://github.com/AbigailWilliams1692/data-retrieval-module/discussions)
|
|
341
|
+
|
|
342
|
+
## Related Projects
|
|
343
|
+
|
|
344
|
+
- [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy) - SQL toolkit and ORM
|
|
345
|
+
- [Django ORM](https://github.com/django/django) - Django's database ORM
|
|
346
|
+
- [Tortoise ORM](https://github.com/tortoise/tortoise-orm) - Async ORM for Python
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
**Made with ❤️ by [AbigailWilliams1692](https://github.com/AbigailWilliams1692)**
|