pyarallel 0.1.0__tar.gz → 0.1.2__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.
- {pyarallel-0.1.0 → pyarallel-0.1.2}/.gitignore +5 -0
- pyarallel-0.1.2/Makefile +36 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/PKG-INFO +159 -2
- {pyarallel-0.1.0 → pyarallel-0.1.2}/README.md +158 -1
- pyarallel-0.1.2/TASKS.md +123 -0
- pyarallel-0.1.2/docs/api-reference/configuration-api.md +49 -0
- pyarallel-0.1.2/docs/api-reference/decorators.md +64 -0
- pyarallel-0.1.2/docs/api-reference/rate-limiting.md +60 -0
- pyarallel-0.1.2/docs/development/CONTRIBUTING.md +56 -0
- pyarallel-0.1.2/docs/development/roadmap.md +74 -0
- pyarallel-0.1.2/docs/getting-started/installation.md +61 -0
- pyarallel-0.1.2/docs/getting-started/quickstart.md +94 -0
- pyarallel-0.1.2/docs/index.md +61 -0
- pyarallel-0.1.2/docs/user-guide/advanced-features.md +174 -0
- pyarallel-0.1.2/docs/user-guide/best-practices.md +207 -0
- pyarallel-0.1.2/docs/user-guide/configuration.md +150 -0
- pyarallel-0.1.2/mkdocs.yml +46 -0
- pyarallel-0.1.2/pyarallel/config.py +172 -0
- pyarallel-0.1.2/pyarallel/config_manager.py +342 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/pyarallel/core.py +69 -120
- pyarallel-0.1.2/pyarallel/env_config.py +57 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/pyproject.toml +13 -1
- pyarallel-0.1.2/sandbox/sandbox_test.py +100 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/setup.py +1 -1
- pyarallel-0.1.2/tests/conftest.py +108 -0
- pyarallel-0.1.2/tests/test_config_manager.py +71 -0
- pyarallel-0.1.2/tests/test_decorator_config.py +121 -0
- pyarallel-0.1.2/tests/test_env_config.py +64 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/tests/test_pyarallel.py +52 -45
- pyarallel-0.1.2/tests/test_runtime_config.py +114 -0
- pyarallel-0.1.2/uv.lock +871 -0
- pyarallel-0.1.0/.coverage.Mehmets-MacBook-Pro.local.1413.XTMkSGtx +0 -0
- pyarallel-0.1.0/hello.py +0 -6
- pyarallel-0.1.0/uv.lock +0 -3056
- {pyarallel-0.1.0 → pyarallel-0.1.2}/.python-version +0 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/CONTRIBUTING.md +0 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/LICENSE.md +0 -0
- {pyarallel-0.1.0 → pyarallel-0.1.2}/pyarallel/__init__.py +0 -0
pyarallel-0.1.2/Makefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.PHONY: help test docs-serve docs-deploy format lint clean
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "Available commands:"
|
|
5
|
+
@echo " make test Run pytest suite"
|
|
6
|
+
@echo " make docs-serve Start mkdocs development server"
|
|
7
|
+
@echo " make docs-deploy Deploy documentation to GitHub Pages"
|
|
8
|
+
@echo " make format Format code with black and isort"
|
|
9
|
+
@echo " make lint Run mypy for type checking"
|
|
10
|
+
@echo " make clean Remove build artifacts"
|
|
11
|
+
|
|
12
|
+
test:
|
|
13
|
+
pytest tests/ -v
|
|
14
|
+
|
|
15
|
+
docs-serve:
|
|
16
|
+
mkdocs serve
|
|
17
|
+
|
|
18
|
+
docs-deploy:
|
|
19
|
+
python -c "import pyarallel; from pathlib import Path; yml = Path('mkdocs.yml').read_text(); Path('mkdocs.yml').write_text(yml.replace('version: .*', f'version: {pyarallel.__version__}'))"
|
|
20
|
+
mkdocs gh-deploy
|
|
21
|
+
|
|
22
|
+
format:
|
|
23
|
+
black .
|
|
24
|
+
isort .
|
|
25
|
+
|
|
26
|
+
lint:
|
|
27
|
+
mypy pyarallel/
|
|
28
|
+
|
|
29
|
+
clean:
|
|
30
|
+
rm -rf build/
|
|
31
|
+
rm -rf dist/
|
|
32
|
+
rm -rf *.egg-info/
|
|
33
|
+
find . -type d -name __pycache__ -exec rm -rf {} +
|
|
34
|
+
find . -type f -name '*.pyc' -delete
|
|
35
|
+
find . -type f -name '*.pyo' -delete
|
|
36
|
+
find . -type f -name '*.pyd' -delete
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyarallel
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A powerful parallel execution library for Python
|
|
5
5
|
Project-URL: Homepage, https://github.com/oneryalcin/pyarallel
|
|
6
6
|
Project-URL: Repository, https://github.com/oneryalcin/pyarallel.git
|
|
@@ -39,6 +39,9 @@ Description-Content-Type: text/markdown
|
|
|
39
39
|
|
|
40
40
|
# Pyarallel
|
|
41
41
|
|
|
42
|
+
[](https://oneryalcin.github.io/pyarallel/) [](https://pypi.org/project/pyarallel/) [](https://pepy.tech/project/pyarallel)
|
|
43
|
+
|
|
44
|
+
|
|
42
45
|
A powerful,feature-rich parallel execution library for Python that makes concurrent programming easy and efficient.
|
|
43
46
|
|
|
44
47
|
## Features
|
|
@@ -56,6 +59,10 @@ A powerful,feature-rich parallel execution library for Python that makes concurr
|
|
|
56
59
|
- Memory-efficient with automatic cleanup
|
|
57
60
|
- Comprehensive error handling
|
|
58
61
|
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
Check out the [documentation](https://oneryalcin.github.io/pyarallel/) for detailed usage instructions and examples.
|
|
65
|
+
|
|
59
66
|
## Installation
|
|
60
67
|
|
|
61
68
|
```bash
|
|
@@ -180,6 +187,157 @@ results = process_large_dataset(items)
|
|
|
180
187
|
return {"error": str(e), "item": item}
|
|
181
188
|
```
|
|
182
189
|
|
|
190
|
+
## Configuration
|
|
191
|
+
|
|
192
|
+
Pyarallel features a robust configuration system built on Pydantic, offering type validation, environment variable support, and thread-safe configuration management.
|
|
193
|
+
|
|
194
|
+
### Basic Configuration
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from pyarallel import ConfigManager
|
|
198
|
+
|
|
199
|
+
# Get the thread-safe singleton configuration manager
|
|
200
|
+
config = ConfigManager.get_instance()
|
|
201
|
+
|
|
202
|
+
# Update configuration with type validation
|
|
203
|
+
config.update_config({
|
|
204
|
+
"execution": {
|
|
205
|
+
"default_max_workers": 8,
|
|
206
|
+
"default_executor_type": "thread",
|
|
207
|
+
"default_batch_size": 100,
|
|
208
|
+
"prewarm_pools": True
|
|
209
|
+
},
|
|
210
|
+
"rate_limiting": {
|
|
211
|
+
"default_rate": 1000,
|
|
212
|
+
"default_interval": "minute",
|
|
213
|
+
"burst_tolerance": 1.5
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
# Access configuration using dot notation
|
|
218
|
+
workers = config.execution.default_max_workers
|
|
219
|
+
rate = config.rate_limiting.default_rate
|
|
220
|
+
|
|
221
|
+
# Category-specific updates
|
|
222
|
+
config.update_execution(max_workers=16)
|
|
223
|
+
config.update_rate_limiting(rate=2000)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Environment Variables
|
|
227
|
+
|
|
228
|
+
Configure Pyarallel using environment variables with the `PYARALLEL_` prefix. The system automatically handles type coercion and validation:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Execution settings
|
|
232
|
+
export PYARALLEL_MAX_WORKERS=4
|
|
233
|
+
export PYARALLEL_EXECUTOR_TYPE=thread
|
|
234
|
+
export PYARALLEL_BATCH_SIZE=100
|
|
235
|
+
|
|
236
|
+
# Rate limiting
|
|
237
|
+
export PYARALLEL_RATE_LIMIT=100/minute
|
|
238
|
+
export PYARALLEL_FAIL_FAST=true
|
|
239
|
+
|
|
240
|
+
# Complex values (using JSON)
|
|
241
|
+
export PYARALLEL_RETRY_CONFIG='{"max_attempts": 3, "backoff": 1.5}'
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Configuration Schema
|
|
245
|
+
|
|
246
|
+
The configuration system uses a structured schema with the following categories:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
{
|
|
250
|
+
"execution": {
|
|
251
|
+
"default_max_workers": int, # Default worker count
|
|
252
|
+
"default_executor_type": str, # "thread" or "process"
|
|
253
|
+
"default_batch_size": Optional[int], # Default batch size
|
|
254
|
+
"prewarm_pools": bool # Enable worker prewarming
|
|
255
|
+
},
|
|
256
|
+
"rate_limiting": {
|
|
257
|
+
"default_rate": Optional[float], # Default operations per interval
|
|
258
|
+
"default_interval": str, # "second", "minute", "hour"
|
|
259
|
+
"burst_tolerance": float # Burst allowance factor
|
|
260
|
+
},
|
|
261
|
+
"error_handling": {
|
|
262
|
+
"max_retries": int, # Maximum retry attempts
|
|
263
|
+
"retry_backoff": float, # Backoff multiplier
|
|
264
|
+
"fail_fast": bool # Stop on first error
|
|
265
|
+
},
|
|
266
|
+
"monitoring": {
|
|
267
|
+
"enable_logging": bool, # Enable detailed logging
|
|
268
|
+
"log_level": str, # Logging level
|
|
269
|
+
"sentry_dsn": Optional[str], # Sentry integration
|
|
270
|
+
"metrics_enabled": bool # Enable metrics collection
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Best Practices
|
|
276
|
+
|
|
277
|
+
1. **Use Environment Variables for Deployment**:
|
|
278
|
+
- Keep configuration in environment variables for different environments
|
|
279
|
+
- Use the `PYARALLEL_` prefix to avoid conflicts
|
|
280
|
+
- Complex values can be passed as JSON strings
|
|
281
|
+
|
|
282
|
+
2. **Validate Configuration Early**:
|
|
283
|
+
- Set up configuration at application startup
|
|
284
|
+
- Use type validation to catch issues early
|
|
285
|
+
- Test configuration with sample data
|
|
286
|
+
|
|
287
|
+
3. **Thread-Safe Updates**:
|
|
288
|
+
- Always use `ConfigManager.get_instance()` for thread-safe access
|
|
289
|
+
- Make configuration changes before starting parallel operations
|
|
290
|
+
- Use category-specific update methods for better type safety
|
|
291
|
+
|
|
292
|
+
4. **Configuration Inheritance**:
|
|
293
|
+
- Global settings serve as defaults
|
|
294
|
+
- Decorator arguments override global configuration
|
|
295
|
+
- Environment variables take precedence over code-based configuration
|
|
296
|
+
|
|
297
|
+
### Runtime Configuration Warnings
|
|
298
|
+
|
|
299
|
+
Pyarallel includes built-in warnings to help identify potential performance issues:
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
# Warning for high worker count
|
|
303
|
+
@parallel(max_workers=150) # Triggers warning about system impact
|
|
304
|
+
def high_worker_task(): ...
|
|
305
|
+
|
|
306
|
+
# Warning for inefficient process pool configuration
|
|
307
|
+
@parallel(
|
|
308
|
+
executor_type="process",
|
|
309
|
+
batch_size=1 # Triggers warning about inefficient batch size
|
|
310
|
+
)
|
|
311
|
+
def inefficient_task(): ...
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Configuration Inheritance
|
|
315
|
+
|
|
316
|
+
Pyarallel uses a hierarchical configuration system:
|
|
317
|
+
|
|
318
|
+
1. **Default Values**: Built-in defaults (4 workers, thread executor, batch size 10)
|
|
319
|
+
2. **Global Configuration**: Set via ConfigManager
|
|
320
|
+
3. **Environment Variables**: Override global config
|
|
321
|
+
4. **Decorator Arguments**: Highest precedence, override all other settings
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
# Global configuration (lowest precedence)
|
|
325
|
+
config = ConfigManager.get_instance()
|
|
326
|
+
config.update_config({
|
|
327
|
+
"execution": {
|
|
328
|
+
"default_max_workers": 8,
|
|
329
|
+
"default_executor_type": "thread"
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
# Environment variables (middle precedence)
|
|
334
|
+
# export PYARALLEL_MAX_WORKERS=16
|
|
335
|
+
|
|
336
|
+
# Decorator arguments (highest precedence)
|
|
337
|
+
@parallel(max_workers=4) # This value wins
|
|
338
|
+
def my_func(): ...
|
|
339
|
+
```
|
|
340
|
+
|
|
183
341
|
## Roadmap
|
|
184
342
|
|
|
185
343
|
### Observability & Debugging
|
|
@@ -235,7 +393,6 @@ results = process_large_dataset(items)
|
|
|
235
393
|
- Log analysis utilities
|
|
236
394
|
- Telemetry visualization
|
|
237
395
|
|
|
238
|
-
|
|
239
396
|
### Enterprise Features
|
|
240
397
|
- **Integration**
|
|
241
398
|
- Distributed tracing (OpenTelemetry)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Pyarallel
|
|
2
2
|
|
|
3
|
+
[](https://oneryalcin.github.io/pyarallel/) [](https://pypi.org/project/pyarallel/) [](https://pepy.tech/project/pyarallel)
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
A powerful,feature-rich parallel execution library for Python that makes concurrent programming easy and efficient.
|
|
4
7
|
|
|
5
8
|
## Features
|
|
@@ -17,6 +20,10 @@ A powerful,feature-rich parallel execution library for Python that makes concurr
|
|
|
17
20
|
- Memory-efficient with automatic cleanup
|
|
18
21
|
- Comprehensive error handling
|
|
19
22
|
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
Check out the [documentation](https://oneryalcin.github.io/pyarallel/) for detailed usage instructions and examples.
|
|
26
|
+
|
|
20
27
|
## Installation
|
|
21
28
|
|
|
22
29
|
```bash
|
|
@@ -141,6 +148,157 @@ results = process_large_dataset(items)
|
|
|
141
148
|
return {"error": str(e), "item": item}
|
|
142
149
|
```
|
|
143
150
|
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
Pyarallel features a robust configuration system built on Pydantic, offering type validation, environment variable support, and thread-safe configuration management.
|
|
154
|
+
|
|
155
|
+
### Basic Configuration
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from pyarallel import ConfigManager
|
|
159
|
+
|
|
160
|
+
# Get the thread-safe singleton configuration manager
|
|
161
|
+
config = ConfigManager.get_instance()
|
|
162
|
+
|
|
163
|
+
# Update configuration with type validation
|
|
164
|
+
config.update_config({
|
|
165
|
+
"execution": {
|
|
166
|
+
"default_max_workers": 8,
|
|
167
|
+
"default_executor_type": "thread",
|
|
168
|
+
"default_batch_size": 100,
|
|
169
|
+
"prewarm_pools": True
|
|
170
|
+
},
|
|
171
|
+
"rate_limiting": {
|
|
172
|
+
"default_rate": 1000,
|
|
173
|
+
"default_interval": "minute",
|
|
174
|
+
"burst_tolerance": 1.5
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
# Access configuration using dot notation
|
|
179
|
+
workers = config.execution.default_max_workers
|
|
180
|
+
rate = config.rate_limiting.default_rate
|
|
181
|
+
|
|
182
|
+
# Category-specific updates
|
|
183
|
+
config.update_execution(max_workers=16)
|
|
184
|
+
config.update_rate_limiting(rate=2000)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Environment Variables
|
|
188
|
+
|
|
189
|
+
Configure Pyarallel using environment variables with the `PYARALLEL_` prefix. The system automatically handles type coercion and validation:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Execution settings
|
|
193
|
+
export PYARALLEL_MAX_WORKERS=4
|
|
194
|
+
export PYARALLEL_EXECUTOR_TYPE=thread
|
|
195
|
+
export PYARALLEL_BATCH_SIZE=100
|
|
196
|
+
|
|
197
|
+
# Rate limiting
|
|
198
|
+
export PYARALLEL_RATE_LIMIT=100/minute
|
|
199
|
+
export PYARALLEL_FAIL_FAST=true
|
|
200
|
+
|
|
201
|
+
# Complex values (using JSON)
|
|
202
|
+
export PYARALLEL_RETRY_CONFIG='{"max_attempts": 3, "backoff": 1.5}'
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Configuration Schema
|
|
206
|
+
|
|
207
|
+
The configuration system uses a structured schema with the following categories:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
{
|
|
211
|
+
"execution": {
|
|
212
|
+
"default_max_workers": int, # Default worker count
|
|
213
|
+
"default_executor_type": str, # "thread" or "process"
|
|
214
|
+
"default_batch_size": Optional[int], # Default batch size
|
|
215
|
+
"prewarm_pools": bool # Enable worker prewarming
|
|
216
|
+
},
|
|
217
|
+
"rate_limiting": {
|
|
218
|
+
"default_rate": Optional[float], # Default operations per interval
|
|
219
|
+
"default_interval": str, # "second", "minute", "hour"
|
|
220
|
+
"burst_tolerance": float # Burst allowance factor
|
|
221
|
+
},
|
|
222
|
+
"error_handling": {
|
|
223
|
+
"max_retries": int, # Maximum retry attempts
|
|
224
|
+
"retry_backoff": float, # Backoff multiplier
|
|
225
|
+
"fail_fast": bool # Stop on first error
|
|
226
|
+
},
|
|
227
|
+
"monitoring": {
|
|
228
|
+
"enable_logging": bool, # Enable detailed logging
|
|
229
|
+
"log_level": str, # Logging level
|
|
230
|
+
"sentry_dsn": Optional[str], # Sentry integration
|
|
231
|
+
"metrics_enabled": bool # Enable metrics collection
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Best Practices
|
|
237
|
+
|
|
238
|
+
1. **Use Environment Variables for Deployment**:
|
|
239
|
+
- Keep configuration in environment variables for different environments
|
|
240
|
+
- Use the `PYARALLEL_` prefix to avoid conflicts
|
|
241
|
+
- Complex values can be passed as JSON strings
|
|
242
|
+
|
|
243
|
+
2. **Validate Configuration Early**:
|
|
244
|
+
- Set up configuration at application startup
|
|
245
|
+
- Use type validation to catch issues early
|
|
246
|
+
- Test configuration with sample data
|
|
247
|
+
|
|
248
|
+
3. **Thread-Safe Updates**:
|
|
249
|
+
- Always use `ConfigManager.get_instance()` for thread-safe access
|
|
250
|
+
- Make configuration changes before starting parallel operations
|
|
251
|
+
- Use category-specific update methods for better type safety
|
|
252
|
+
|
|
253
|
+
4. **Configuration Inheritance**:
|
|
254
|
+
- Global settings serve as defaults
|
|
255
|
+
- Decorator arguments override global configuration
|
|
256
|
+
- Environment variables take precedence over code-based configuration
|
|
257
|
+
|
|
258
|
+
### Runtime Configuration Warnings
|
|
259
|
+
|
|
260
|
+
Pyarallel includes built-in warnings to help identify potential performance issues:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
# Warning for high worker count
|
|
264
|
+
@parallel(max_workers=150) # Triggers warning about system impact
|
|
265
|
+
def high_worker_task(): ...
|
|
266
|
+
|
|
267
|
+
# Warning for inefficient process pool configuration
|
|
268
|
+
@parallel(
|
|
269
|
+
executor_type="process",
|
|
270
|
+
batch_size=1 # Triggers warning about inefficient batch size
|
|
271
|
+
)
|
|
272
|
+
def inefficient_task(): ...
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Configuration Inheritance
|
|
276
|
+
|
|
277
|
+
Pyarallel uses a hierarchical configuration system:
|
|
278
|
+
|
|
279
|
+
1. **Default Values**: Built-in defaults (4 workers, thread executor, batch size 10)
|
|
280
|
+
2. **Global Configuration**: Set via ConfigManager
|
|
281
|
+
3. **Environment Variables**: Override global config
|
|
282
|
+
4. **Decorator Arguments**: Highest precedence, override all other settings
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
# Global configuration (lowest precedence)
|
|
286
|
+
config = ConfigManager.get_instance()
|
|
287
|
+
config.update_config({
|
|
288
|
+
"execution": {
|
|
289
|
+
"default_max_workers": 8,
|
|
290
|
+
"default_executor_type": "thread"
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
# Environment variables (middle precedence)
|
|
295
|
+
# export PYARALLEL_MAX_WORKERS=16
|
|
296
|
+
|
|
297
|
+
# Decorator arguments (highest precedence)
|
|
298
|
+
@parallel(max_workers=4) # This value wins
|
|
299
|
+
def my_func(): ...
|
|
300
|
+
```
|
|
301
|
+
|
|
144
302
|
## Roadmap
|
|
145
303
|
|
|
146
304
|
### Observability & Debugging
|
|
@@ -196,7 +354,6 @@ results = process_large_dataset(items)
|
|
|
196
354
|
- Log analysis utilities
|
|
197
355
|
- Telemetry visualization
|
|
198
356
|
|
|
199
|
-
|
|
200
357
|
### Enterprise Features
|
|
201
358
|
- **Integration**
|
|
202
359
|
- Distributed tracing (OpenTelemetry)
|
pyarallel-0.1.2/TASKS.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Configuration System Implementation Tasks
|
|
2
|
+
|
|
3
|
+
## 1. Core Configuration System [✅]
|
|
4
|
+
- [✅] Create `config.py` with dataclass-based configuration
|
|
5
|
+
- [✅] Implement singleton config manager
|
|
6
|
+
- [✅] Add type validation for config values
|
|
7
|
+
- [✅] Add merge strategy for partial updates
|
|
8
|
+
|
|
9
|
+
**Test Cases:**
|
|
10
|
+
```python
|
|
11
|
+
def test_config_defaults():
|
|
12
|
+
"""Default values are set correctly"""
|
|
13
|
+
|
|
14
|
+
def test_config_validation():
|
|
15
|
+
"""Invalid values raise proper exceptions"""
|
|
16
|
+
|
|
17
|
+
def test_partial_update():
|
|
18
|
+
"""Partial config updates don't affect other values"""
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 2. Environment Variables Support [✅]
|
|
22
|
+
- [✅] Add env var parsing in config manager
|
|
23
|
+
- [✅] Implement type coercion (str -> proper type)
|
|
24
|
+
- [✅] Add prefix support (PYARALLEL_*)
|
|
25
|
+
- [✅] Support complex values (lists, dicts via JSON)
|
|
26
|
+
|
|
27
|
+
**Test Cases:**
|
|
28
|
+
```python
|
|
29
|
+
def test_env_var_loading():
|
|
30
|
+
"""Config loads from environment variables"""
|
|
31
|
+
|
|
32
|
+
def test_env_var_types():
|
|
33
|
+
"""Environment variables are properly typed"""
|
|
34
|
+
|
|
35
|
+
def test_env_var_prefix():
|
|
36
|
+
"""Only PYARALLEL_* vars are loaded"""
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 3. Runtime Configuration API [✅]
|
|
40
|
+
- [✅] Add global `set()` method
|
|
41
|
+
- [✅] Add category-specific setters
|
|
42
|
+
- [✅] Add value getters with dot notation
|
|
43
|
+
- [✅] Implement config validation hooks
|
|
44
|
+
|
|
45
|
+
**Test Cases:**
|
|
46
|
+
```python
|
|
47
|
+
def test_global_set():
|
|
48
|
+
"""Global config can be set"""
|
|
49
|
+
|
|
50
|
+
def test_category_set():
|
|
51
|
+
"""Category-specific settings work"""
|
|
52
|
+
|
|
53
|
+
def test_dot_notation():
|
|
54
|
+
"""Dot notation access works for nested config"""
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 4. Decorator Integration [✅]
|
|
58
|
+
- [✅] Update parallel decorator to use config
|
|
59
|
+
- [✅] Add config override in decorator
|
|
60
|
+
- [✅] Implement inheritance rules
|
|
61
|
+
- [✅] Add runtime config warnings
|
|
62
|
+
|
|
63
|
+
**Test Cases:**
|
|
64
|
+
```python
|
|
65
|
+
def test_decorator_defaults():
|
|
66
|
+
"""Decorator uses global defaults"""
|
|
67
|
+
|
|
68
|
+
def test_decorator_override():
|
|
69
|
+
"""Decorator args override global config"""
|
|
70
|
+
|
|
71
|
+
def test_runtime_warnings():
|
|
72
|
+
"""Warnings for problematic configs"""
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 5. Documentation [ ]
|
|
76
|
+
- [ ] Add configuration section to README
|
|
77
|
+
- [ ] Document all environment variables
|
|
78
|
+
- [ ] Add configuration examples
|
|
79
|
+
- [ ] Document best practices
|
|
80
|
+
|
|
81
|
+
## Configuration Schema
|
|
82
|
+
```python
|
|
83
|
+
{
|
|
84
|
+
"execution": {
|
|
85
|
+
"default_max_workers": int,
|
|
86
|
+
"default_executor_type": str,
|
|
87
|
+
"default_batch_size": Optional[int],
|
|
88
|
+
"prewarm_pools": bool
|
|
89
|
+
},
|
|
90
|
+
"rate_limiting": {
|
|
91
|
+
"default_rate": Optional[float],
|
|
92
|
+
"default_interval": str,
|
|
93
|
+
"burst_tolerance": float
|
|
94
|
+
},
|
|
95
|
+
"error_handling": {
|
|
96
|
+
"max_retries": int,
|
|
97
|
+
"retry_backoff": float,
|
|
98
|
+
"fail_fast": bool
|
|
99
|
+
},
|
|
100
|
+
"monitoring": {
|
|
101
|
+
"enable_logging": bool,
|
|
102
|
+
"log_level": str,
|
|
103
|
+
"sentry_dsn": Optional[str],
|
|
104
|
+
"metrics_enabled": bool
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Environment Variables
|
|
110
|
+
```
|
|
111
|
+
PYARALLEL_MAX_WORKERS=4
|
|
112
|
+
PYARALLEL_EXECUTOR_TYPE=thread
|
|
113
|
+
PYARALLEL_BATCH_SIZE=10
|
|
114
|
+
PYARALLEL_RATE_LIMIT=100/minute
|
|
115
|
+
PYARALLEL_FAIL_FAST=true
|
|
116
|
+
PYARALLEL_SENTRY_DSN=https://...
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Progress Tracking
|
|
120
|
+
- ✅ Task completed
|
|
121
|
+
- 🚧 In progress
|
|
122
|
+
- ❌ Blocked
|
|
123
|
+
- [ ] Not started
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Configuration API
|
|
4
|
+
|
|
5
|
+
### ConfigManager
|
|
6
|
+
|
|
7
|
+
Singleton class for managing global configuration.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pyarallel import ConfigManager
|
|
11
|
+
|
|
12
|
+
config_manager = ConfigManager.get_instance()
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
#### Methods
|
|
16
|
+
|
|
17
|
+
- `get_config()`: Get current configuration
|
|
18
|
+
- `update_config(config: dict)`: Update configuration with new values
|
|
19
|
+
- `reset_config()`: Reset to default configuration
|
|
20
|
+
|
|
21
|
+
#### Configuration Options
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
{
|
|
25
|
+
"execution": {
|
|
26
|
+
"default_max_workers": 4,
|
|
27
|
+
"default_executor_type": "thread",
|
|
28
|
+
"default_batch_size": 10
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### Examples
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
# Get config manager instance
|
|
37
|
+
config_manager = ConfigManager.get_instance()
|
|
38
|
+
|
|
39
|
+
# Update global configuration
|
|
40
|
+
config_manager.update_config({
|
|
41
|
+
"execution": {
|
|
42
|
+
"default_max_workers": 8,
|
|
43
|
+
"default_executor_type": "process"
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
# Get current configuration
|
|
48
|
+
config = config_manager.get_config()
|
|
49
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Decorator API
|
|
4
|
+
|
|
5
|
+
### @parallel
|
|
6
|
+
|
|
7
|
+
The main decorator for enabling parallel execution of functions.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from pyarallel import parallel
|
|
11
|
+
|
|
12
|
+
@parallel(
|
|
13
|
+
max_workers: int = None,
|
|
14
|
+
batch_size: int = None,
|
|
15
|
+
rate_limit: float | tuple[float, TimeUnit] | RateLimit = None,
|
|
16
|
+
executor_type: Literal["thread", "process"] = None,
|
|
17
|
+
prewarm: bool = False
|
|
18
|
+
)
|
|
19
|
+
def function(item, *args, **kwargs) -> Any: ...
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### Parameters
|
|
23
|
+
|
|
24
|
+
- `max_workers` (int, optional): Maximum number of parallel workers. Defaults to global configuration.
|
|
25
|
+
- `batch_size` (int, optional): Number of items to process in each batch. Defaults to global configuration.
|
|
26
|
+
- `rate_limit`: Rate limiting configuration. Can be:
|
|
27
|
+
- A float (operations per second)
|
|
28
|
+
- A tuple of (count, unit) where unit is "second", "minute", or "hour"
|
|
29
|
+
- A RateLimit instance
|
|
30
|
+
- `executor_type` (str, optional): Type of parallelism to use ("thread" or "process"). Defaults to global configuration.
|
|
31
|
+
- `prewarm` (bool): If True, starts all workers immediately.
|
|
32
|
+
|
|
33
|
+
#### Returns
|
|
34
|
+
|
|
35
|
+
A wrapped function that accepts either:
|
|
36
|
+
- A single item (returns a single-item list)
|
|
37
|
+
- A list/tuple of items (processes in parallel and returns a list of results)
|
|
38
|
+
|
|
39
|
+
#### Examples
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
# Basic usage with threads
|
|
43
|
+
@parallel(max_workers=4)
|
|
44
|
+
def fetch_url(url: str) -> dict:
|
|
45
|
+
return requests.get(url).json()
|
|
46
|
+
|
|
47
|
+
# Process-based execution with rate limiting
|
|
48
|
+
@parallel(
|
|
49
|
+
max_workers=4,
|
|
50
|
+
executor_type="process",
|
|
51
|
+
rate_limit=(100, "minute")
|
|
52
|
+
)
|
|
53
|
+
def process_image(image: bytes) -> bytes:
|
|
54
|
+
return heavy_processing(image)
|
|
55
|
+
|
|
56
|
+
# Batch processing with prewarming
|
|
57
|
+
@parallel(
|
|
58
|
+
max_workers=4,
|
|
59
|
+
batch_size=10,
|
|
60
|
+
prewarm=True
|
|
61
|
+
)
|
|
62
|
+
def analyze_text(text: str) -> dict:
|
|
63
|
+
return text_analysis(text)
|
|
64
|
+
```
|