pyarallel 0.1.1__tar.gz → 0.1.3__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.1 → pyarallel-0.1.3}/.gitignore +4 -0
- pyarallel-0.1.3/Makefile +36 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/PKG-INFO +210 -60
- {pyarallel-0.1.1 → pyarallel-0.1.3}/README.md +209 -59
- pyarallel-0.1.3/TASKS.md +153 -0
- pyarallel-0.1.3/docs/api-reference/configuration-api.md +49 -0
- pyarallel-0.1.3/docs/api-reference/decorators.md +64 -0
- pyarallel-0.1.3/docs/api-reference/rate-limiting.md +60 -0
- pyarallel-0.1.3/docs/development/CONTRIBUTING.md +56 -0
- pyarallel-0.1.3/docs/development/roadmap.md +78 -0
- pyarallel-0.1.3/docs/getting-started/installation.md +61 -0
- pyarallel-0.1.3/docs/getting-started/quickstart.md +94 -0
- pyarallel-0.1.3/docs/index.md +101 -0
- pyarallel-0.1.3/docs/user-guide/advanced-features.md +174 -0
- pyarallel-0.1.3/docs/user-guide/best-practices.md +207 -0
- pyarallel-0.1.3/docs/user-guide/configuration.md +150 -0
- pyarallel-0.1.3/mkdocs.yml +46 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/pyarallel/__init__.py +2 -2
- {pyarallel-0.1.1 → pyarallel-0.1.3}/pyarallel/config.py +64 -20
- pyarallel-0.1.3/pyarallel/config_manager.py +368 -0
- pyarallel-0.1.3/pyarallel/core.py +414 -0
- pyarallel-0.1.3/pyarallel/env_config.py +58 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/pyproject.toml +13 -1
- pyarallel-0.1.3/sandbox/sandbox_test.py +91 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/setup.py +2 -2
- pyarallel-0.1.3/tests/conftest.py +120 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/tests/test_config_manager.py +28 -29
- pyarallel-0.1.3/tests/test_decorator_config.py +127 -0
- pyarallel-0.1.3/tests/test_env_config.py +68 -0
- pyarallel-0.1.3/tests/test_pyarallel.py +184 -0
- pyarallel-0.1.3/tests/test_runtime_config.py +119 -0
- pyarallel-0.1.3/uv.lock +871 -0
- pyarallel-0.1.1/TASKS.md +0 -123
- pyarallel-0.1.1/pyarallel/config_manager.py +0 -90
- pyarallel-0.1.1/pyarallel/core.py +0 -348
- pyarallel-0.1.1/tests/test_pyarallel.py +0 -92
- pyarallel-0.1.1/uv.lock +0 -7
- {pyarallel-0.1.1 → pyarallel-0.1.3}/.python-version +0 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/CONTRIBUTING.md +0 -0
- {pyarallel-0.1.1 → pyarallel-0.1.3}/LICENSE.md +0 -0
pyarallel-0.1.3/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.3
|
|
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
|
|
@@ -91,6 +98,56 @@ def analyze_text(text: str) -> dict:
|
|
|
91
98
|
return text_analysis(text)
|
|
92
99
|
```
|
|
93
100
|
|
|
101
|
+
## Usage Examples
|
|
102
|
+
|
|
103
|
+
### Basic Function
|
|
104
|
+
```python
|
|
105
|
+
from pyarallel import parallel
|
|
106
|
+
|
|
107
|
+
@parallel
|
|
108
|
+
def process_item(x):
|
|
109
|
+
return x * 2
|
|
110
|
+
|
|
111
|
+
results = process_item([1, 2, 3]) # [2, 4, 6]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Instance Methods
|
|
115
|
+
```python
|
|
116
|
+
class DataProcessor:
|
|
117
|
+
def __init__(self, multiplier):
|
|
118
|
+
self.multiplier = multiplier
|
|
119
|
+
|
|
120
|
+
@parallel
|
|
121
|
+
def process(self, x):
|
|
122
|
+
return x * self.multiplier
|
|
123
|
+
|
|
124
|
+
processor = DataProcessor(3)
|
|
125
|
+
results = processor.process([1, 2, 3]) # [3, 6, 9]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Class Methods
|
|
129
|
+
```python
|
|
130
|
+
class StringFormatter:
|
|
131
|
+
@classmethod
|
|
132
|
+
@parallel
|
|
133
|
+
def format_all(cls, items):
|
|
134
|
+
return [f"Formatted-{item}" for item in items]
|
|
135
|
+
|
|
136
|
+
results = StringFormatter.format_all(['a', 'b', 'c'])
|
|
137
|
+
# ['Formatted-a', 'Formatted-b', 'Formatted-c']
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Static Methods
|
|
141
|
+
```python
|
|
142
|
+
class MathUtils:
|
|
143
|
+
@staticmethod
|
|
144
|
+
@parallel
|
|
145
|
+
def square_all(numbers):
|
|
146
|
+
return [n**2 for n in numbers]
|
|
147
|
+
|
|
148
|
+
results = MathUtils.square_all([1, 2, 3]) # [1, 4, 9]
|
|
149
|
+
```
|
|
150
|
+
|
|
94
151
|
## Advanced Usage
|
|
95
152
|
|
|
96
153
|
### Rate Limiting
|
|
@@ -180,6 +237,157 @@ results = process_large_dataset(items)
|
|
|
180
237
|
return {"error": str(e), "item": item}
|
|
181
238
|
```
|
|
182
239
|
|
|
240
|
+
## Configuration
|
|
241
|
+
|
|
242
|
+
Pyarallel features a robust configuration system built on Pydantic, offering type validation, environment variable support, and thread-safe configuration management.
|
|
243
|
+
|
|
244
|
+
### Basic Configuration
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from pyarallel import ConfigManager
|
|
248
|
+
|
|
249
|
+
# Get the thread-safe singleton configuration manager
|
|
250
|
+
config = ConfigManager.get_instance()
|
|
251
|
+
|
|
252
|
+
# Update configuration with type validation
|
|
253
|
+
config.update_config({
|
|
254
|
+
"execution": {
|
|
255
|
+
"default_max_workers": 8,
|
|
256
|
+
"default_executor_type": "thread",
|
|
257
|
+
"default_batch_size": 100,
|
|
258
|
+
"prewarm_pools": True
|
|
259
|
+
},
|
|
260
|
+
"rate_limiting": {
|
|
261
|
+
"default_rate": 1000,
|
|
262
|
+
"default_interval": "minute",
|
|
263
|
+
"burst_tolerance": 1.5
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
# Access configuration using dot notation
|
|
268
|
+
workers = config.execution.default_max_workers
|
|
269
|
+
rate = config.rate_limiting.default_rate
|
|
270
|
+
|
|
271
|
+
# Category-specific updates
|
|
272
|
+
config.update_execution(max_workers=16)
|
|
273
|
+
config.update_rate_limiting(rate=2000)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Environment Variables
|
|
277
|
+
|
|
278
|
+
Configure Pyarallel using environment variables with the `PYARALLEL_` prefix. The system automatically handles type coercion and validation:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# Execution settings
|
|
282
|
+
export PYARALLEL_MAX_WORKERS=4
|
|
283
|
+
export PYARALLEL_EXECUTOR_TYPE=thread
|
|
284
|
+
export PYARALLEL_BATCH_SIZE=100
|
|
285
|
+
|
|
286
|
+
# Rate limiting
|
|
287
|
+
export PYARALLEL_RATE_LIMIT=100/minute
|
|
288
|
+
export PYARALLEL_FAIL_FAST=true
|
|
289
|
+
|
|
290
|
+
# Complex values (using JSON)
|
|
291
|
+
export PYARALLEL_RETRY_CONFIG='{"max_attempts": 3, "backoff": 1.5}'
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Configuration Schema
|
|
295
|
+
|
|
296
|
+
The configuration system uses a structured schema with the following categories:
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
{
|
|
300
|
+
"execution": {
|
|
301
|
+
"default_max_workers": int, # Default worker count
|
|
302
|
+
"default_executor_type": str, # "thread" or "process"
|
|
303
|
+
"default_batch_size": Optional[int], # Default batch size
|
|
304
|
+
"prewarm_pools": bool # Enable worker prewarming
|
|
305
|
+
},
|
|
306
|
+
"rate_limiting": {
|
|
307
|
+
"default_rate": Optional[float], # Default operations per interval
|
|
308
|
+
"default_interval": str, # "second", "minute", "hour"
|
|
309
|
+
"burst_tolerance": float # Burst allowance factor
|
|
310
|
+
},
|
|
311
|
+
"error_handling": {
|
|
312
|
+
"max_retries": int, # Maximum retry attempts
|
|
313
|
+
"retry_backoff": float, # Backoff multiplier
|
|
314
|
+
"fail_fast": bool # Stop on first error
|
|
315
|
+
},
|
|
316
|
+
"monitoring": {
|
|
317
|
+
"enable_logging": bool, # Enable detailed logging
|
|
318
|
+
"log_level": str, # Logging level
|
|
319
|
+
"sentry_dsn": Optional[str], # Sentry integration
|
|
320
|
+
"metrics_enabled": bool # Enable metrics collection
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Best Practices
|
|
326
|
+
|
|
327
|
+
1. **Use Environment Variables for Deployment**:
|
|
328
|
+
- Keep configuration in environment variables for different environments
|
|
329
|
+
- Use the `PYARALLEL_` prefix to avoid conflicts
|
|
330
|
+
- Complex values can be passed as JSON strings
|
|
331
|
+
|
|
332
|
+
2. **Validate Configuration Early**:
|
|
333
|
+
- Set up configuration at application startup
|
|
334
|
+
- Use type validation to catch issues early
|
|
335
|
+
- Test configuration with sample data
|
|
336
|
+
|
|
337
|
+
3. **Thread-Safe Updates**:
|
|
338
|
+
- Always use `ConfigManager.get_instance()` for thread-safe access
|
|
339
|
+
- Make configuration changes before starting parallel operations
|
|
340
|
+
- Use category-specific update methods for better type safety
|
|
341
|
+
|
|
342
|
+
4. **Configuration Inheritance**:
|
|
343
|
+
- Global settings serve as defaults
|
|
344
|
+
- Decorator arguments override global configuration
|
|
345
|
+
- Environment variables take precedence over code-based configuration
|
|
346
|
+
|
|
347
|
+
### Runtime Configuration Warnings
|
|
348
|
+
|
|
349
|
+
Pyarallel includes built-in warnings to help identify potential performance issues:
|
|
350
|
+
|
|
351
|
+
```python
|
|
352
|
+
# Warning for high worker count
|
|
353
|
+
@parallel(max_workers=150) # Triggers warning about system impact
|
|
354
|
+
def high_worker_task(): ...
|
|
355
|
+
|
|
356
|
+
# Warning for inefficient process pool configuration
|
|
357
|
+
@parallel(
|
|
358
|
+
executor_type="process",
|
|
359
|
+
batch_size=1 # Triggers warning about inefficient batch size
|
|
360
|
+
)
|
|
361
|
+
def inefficient_task(): ...
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Configuration Inheritance
|
|
365
|
+
|
|
366
|
+
Pyarallel uses a hierarchical configuration system:
|
|
367
|
+
|
|
368
|
+
1. **Default Values**: Built-in defaults (4 workers, thread executor, batch size 10)
|
|
369
|
+
2. **Global Configuration**: Set via ConfigManager
|
|
370
|
+
3. **Environment Variables**: Override global config
|
|
371
|
+
4. **Decorator Arguments**: Highest precedence, override all other settings
|
|
372
|
+
|
|
373
|
+
```python
|
|
374
|
+
# Global configuration (lowest precedence)
|
|
375
|
+
config = ConfigManager.get_instance()
|
|
376
|
+
config.update_config({
|
|
377
|
+
"execution": {
|
|
378
|
+
"default_max_workers": 8,
|
|
379
|
+
"default_executor_type": "thread"
|
|
380
|
+
}
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
# Environment variables (middle precedence)
|
|
384
|
+
# export PYARALLEL_MAX_WORKERS=16
|
|
385
|
+
|
|
386
|
+
# Decorator arguments (highest precedence)
|
|
387
|
+
@parallel(max_workers=4) # This value wins
|
|
388
|
+
def my_func(): ...
|
|
389
|
+
```
|
|
390
|
+
|
|
183
391
|
## Roadmap
|
|
184
392
|
|
|
185
393
|
### Observability & Debugging
|
|
@@ -235,7 +443,6 @@ results = process_large_dataset(items)
|
|
|
235
443
|
- Log analysis utilities
|
|
236
444
|
- Telemetry visualization
|
|
237
445
|
|
|
238
|
-
|
|
239
446
|
### Enterprise Features
|
|
240
447
|
- **Integration**
|
|
241
448
|
- Distributed tracing (OpenTelemetry)
|
|
@@ -280,61 +487,4 @@ Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTIN
|
|
|
280
487
|
|
|
281
488
|
## License
|
|
282
489
|
|
|
283
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
284
|
-
|
|
285
|
-
## Configuration
|
|
286
|
-
|
|
287
|
-
Pyarallel provides a flexible configuration system that allows you to customize its behavior globally or per-function:
|
|
288
|
-
|
|
289
|
-
### Basic Configuration
|
|
290
|
-
|
|
291
|
-
```python
|
|
292
|
-
from pyarallel import ConfigManager
|
|
293
|
-
|
|
294
|
-
# Get the global configuration manager
|
|
295
|
-
config = ConfigManager.get_instance()
|
|
296
|
-
|
|
297
|
-
# Update configuration
|
|
298
|
-
config.update_config({
|
|
299
|
-
"max_workers": 8,
|
|
300
|
-
"timeout": 60.0,
|
|
301
|
-
"debug": True
|
|
302
|
-
})
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
### Configuration Options
|
|
306
|
-
|
|
307
|
-
- **Execution Settings**
|
|
308
|
-
- `max_workers`: Maximum number of worker processes/threads (default: 4)
|
|
309
|
-
- `timeout`: Default timeout for parallel operations in seconds (default: 30.0)
|
|
310
|
-
|
|
311
|
-
- **Resource Management**
|
|
312
|
-
- `memory_limit`: Memory limit per worker in bytes (default: None)
|
|
313
|
-
- `cpu_affinity`: Enable CPU affinity for workers (default: False)
|
|
314
|
-
|
|
315
|
-
- **Logging and Debugging**
|
|
316
|
-
- `debug`: Enable debug mode (default: False)
|
|
317
|
-
- `log_level`: Logging level (default: "INFO")
|
|
318
|
-
|
|
319
|
-
### Environment Variables
|
|
320
|
-
|
|
321
|
-
You can configure Pyarallel using environment variables with the `PYARALLEL_` prefix:
|
|
322
|
-
|
|
323
|
-
```bash
|
|
324
|
-
PYARALLEL_MAX_WORKERS=4
|
|
325
|
-
PYARALLEL_TIMEOUT=60.0
|
|
326
|
-
PYARALLEL_DEBUG=true
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### Configuration Files
|
|
330
|
-
|
|
331
|
-
Load configuration from JSON, YAML, or TOML files:
|
|
332
|
-
|
|
333
|
-
```python
|
|
334
|
-
from pyarallel import PyarallelConfig
|
|
335
|
-
|
|
336
|
-
# Load from file
|
|
337
|
-
config = PyarallelConfig.from_file("pyarallel.yaml")
|
|
338
|
-
|
|
339
|
-
# Convert to dictionary
|
|
340
|
-
config_dict = config.to_dict()
|
|
490
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -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
|
|
@@ -52,6 +59,56 @@ def analyze_text(text: str) -> dict:
|
|
|
52
59
|
return text_analysis(text)
|
|
53
60
|
```
|
|
54
61
|
|
|
62
|
+
## Usage Examples
|
|
63
|
+
|
|
64
|
+
### Basic Function
|
|
65
|
+
```python
|
|
66
|
+
from pyarallel import parallel
|
|
67
|
+
|
|
68
|
+
@parallel
|
|
69
|
+
def process_item(x):
|
|
70
|
+
return x * 2
|
|
71
|
+
|
|
72
|
+
results = process_item([1, 2, 3]) # [2, 4, 6]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Instance Methods
|
|
76
|
+
```python
|
|
77
|
+
class DataProcessor:
|
|
78
|
+
def __init__(self, multiplier):
|
|
79
|
+
self.multiplier = multiplier
|
|
80
|
+
|
|
81
|
+
@parallel
|
|
82
|
+
def process(self, x):
|
|
83
|
+
return x * self.multiplier
|
|
84
|
+
|
|
85
|
+
processor = DataProcessor(3)
|
|
86
|
+
results = processor.process([1, 2, 3]) # [3, 6, 9]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Class Methods
|
|
90
|
+
```python
|
|
91
|
+
class StringFormatter:
|
|
92
|
+
@classmethod
|
|
93
|
+
@parallel
|
|
94
|
+
def format_all(cls, items):
|
|
95
|
+
return [f"Formatted-{item}" for item in items]
|
|
96
|
+
|
|
97
|
+
results = StringFormatter.format_all(['a', 'b', 'c'])
|
|
98
|
+
# ['Formatted-a', 'Formatted-b', 'Formatted-c']
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Static Methods
|
|
102
|
+
```python
|
|
103
|
+
class MathUtils:
|
|
104
|
+
@staticmethod
|
|
105
|
+
@parallel
|
|
106
|
+
def square_all(numbers):
|
|
107
|
+
return [n**2 for n in numbers]
|
|
108
|
+
|
|
109
|
+
results = MathUtils.square_all([1, 2, 3]) # [1, 4, 9]
|
|
110
|
+
```
|
|
111
|
+
|
|
55
112
|
## Advanced Usage
|
|
56
113
|
|
|
57
114
|
### Rate Limiting
|
|
@@ -141,6 +198,157 @@ results = process_large_dataset(items)
|
|
|
141
198
|
return {"error": str(e), "item": item}
|
|
142
199
|
```
|
|
143
200
|
|
|
201
|
+
## Configuration
|
|
202
|
+
|
|
203
|
+
Pyarallel features a robust configuration system built on Pydantic, offering type validation, environment variable support, and thread-safe configuration management.
|
|
204
|
+
|
|
205
|
+
### Basic Configuration
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from pyarallel import ConfigManager
|
|
209
|
+
|
|
210
|
+
# Get the thread-safe singleton configuration manager
|
|
211
|
+
config = ConfigManager.get_instance()
|
|
212
|
+
|
|
213
|
+
# Update configuration with type validation
|
|
214
|
+
config.update_config({
|
|
215
|
+
"execution": {
|
|
216
|
+
"default_max_workers": 8,
|
|
217
|
+
"default_executor_type": "thread",
|
|
218
|
+
"default_batch_size": 100,
|
|
219
|
+
"prewarm_pools": True
|
|
220
|
+
},
|
|
221
|
+
"rate_limiting": {
|
|
222
|
+
"default_rate": 1000,
|
|
223
|
+
"default_interval": "minute",
|
|
224
|
+
"burst_tolerance": 1.5
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
# Access configuration using dot notation
|
|
229
|
+
workers = config.execution.default_max_workers
|
|
230
|
+
rate = config.rate_limiting.default_rate
|
|
231
|
+
|
|
232
|
+
# Category-specific updates
|
|
233
|
+
config.update_execution(max_workers=16)
|
|
234
|
+
config.update_rate_limiting(rate=2000)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Environment Variables
|
|
238
|
+
|
|
239
|
+
Configure Pyarallel using environment variables with the `PYARALLEL_` prefix. The system automatically handles type coercion and validation:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Execution settings
|
|
243
|
+
export PYARALLEL_MAX_WORKERS=4
|
|
244
|
+
export PYARALLEL_EXECUTOR_TYPE=thread
|
|
245
|
+
export PYARALLEL_BATCH_SIZE=100
|
|
246
|
+
|
|
247
|
+
# Rate limiting
|
|
248
|
+
export PYARALLEL_RATE_LIMIT=100/minute
|
|
249
|
+
export PYARALLEL_FAIL_FAST=true
|
|
250
|
+
|
|
251
|
+
# Complex values (using JSON)
|
|
252
|
+
export PYARALLEL_RETRY_CONFIG='{"max_attempts": 3, "backoff": 1.5}'
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Configuration Schema
|
|
256
|
+
|
|
257
|
+
The configuration system uses a structured schema with the following categories:
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
{
|
|
261
|
+
"execution": {
|
|
262
|
+
"default_max_workers": int, # Default worker count
|
|
263
|
+
"default_executor_type": str, # "thread" or "process"
|
|
264
|
+
"default_batch_size": Optional[int], # Default batch size
|
|
265
|
+
"prewarm_pools": bool # Enable worker prewarming
|
|
266
|
+
},
|
|
267
|
+
"rate_limiting": {
|
|
268
|
+
"default_rate": Optional[float], # Default operations per interval
|
|
269
|
+
"default_interval": str, # "second", "minute", "hour"
|
|
270
|
+
"burst_tolerance": float # Burst allowance factor
|
|
271
|
+
},
|
|
272
|
+
"error_handling": {
|
|
273
|
+
"max_retries": int, # Maximum retry attempts
|
|
274
|
+
"retry_backoff": float, # Backoff multiplier
|
|
275
|
+
"fail_fast": bool # Stop on first error
|
|
276
|
+
},
|
|
277
|
+
"monitoring": {
|
|
278
|
+
"enable_logging": bool, # Enable detailed logging
|
|
279
|
+
"log_level": str, # Logging level
|
|
280
|
+
"sentry_dsn": Optional[str], # Sentry integration
|
|
281
|
+
"metrics_enabled": bool # Enable metrics collection
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Best Practices
|
|
287
|
+
|
|
288
|
+
1. **Use Environment Variables for Deployment**:
|
|
289
|
+
- Keep configuration in environment variables for different environments
|
|
290
|
+
- Use the `PYARALLEL_` prefix to avoid conflicts
|
|
291
|
+
- Complex values can be passed as JSON strings
|
|
292
|
+
|
|
293
|
+
2. **Validate Configuration Early**:
|
|
294
|
+
- Set up configuration at application startup
|
|
295
|
+
- Use type validation to catch issues early
|
|
296
|
+
- Test configuration with sample data
|
|
297
|
+
|
|
298
|
+
3. **Thread-Safe Updates**:
|
|
299
|
+
- Always use `ConfigManager.get_instance()` for thread-safe access
|
|
300
|
+
- Make configuration changes before starting parallel operations
|
|
301
|
+
- Use category-specific update methods for better type safety
|
|
302
|
+
|
|
303
|
+
4. **Configuration Inheritance**:
|
|
304
|
+
- Global settings serve as defaults
|
|
305
|
+
- Decorator arguments override global configuration
|
|
306
|
+
- Environment variables take precedence over code-based configuration
|
|
307
|
+
|
|
308
|
+
### Runtime Configuration Warnings
|
|
309
|
+
|
|
310
|
+
Pyarallel includes built-in warnings to help identify potential performance issues:
|
|
311
|
+
|
|
312
|
+
```python
|
|
313
|
+
# Warning for high worker count
|
|
314
|
+
@parallel(max_workers=150) # Triggers warning about system impact
|
|
315
|
+
def high_worker_task(): ...
|
|
316
|
+
|
|
317
|
+
# Warning for inefficient process pool configuration
|
|
318
|
+
@parallel(
|
|
319
|
+
executor_type="process",
|
|
320
|
+
batch_size=1 # Triggers warning about inefficient batch size
|
|
321
|
+
)
|
|
322
|
+
def inefficient_task(): ...
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Configuration Inheritance
|
|
326
|
+
|
|
327
|
+
Pyarallel uses a hierarchical configuration system:
|
|
328
|
+
|
|
329
|
+
1. **Default Values**: Built-in defaults (4 workers, thread executor, batch size 10)
|
|
330
|
+
2. **Global Configuration**: Set via ConfigManager
|
|
331
|
+
3. **Environment Variables**: Override global config
|
|
332
|
+
4. **Decorator Arguments**: Highest precedence, override all other settings
|
|
333
|
+
|
|
334
|
+
```python
|
|
335
|
+
# Global configuration (lowest precedence)
|
|
336
|
+
config = ConfigManager.get_instance()
|
|
337
|
+
config.update_config({
|
|
338
|
+
"execution": {
|
|
339
|
+
"default_max_workers": 8,
|
|
340
|
+
"default_executor_type": "thread"
|
|
341
|
+
}
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
# Environment variables (middle precedence)
|
|
345
|
+
# export PYARALLEL_MAX_WORKERS=16
|
|
346
|
+
|
|
347
|
+
# Decorator arguments (highest precedence)
|
|
348
|
+
@parallel(max_workers=4) # This value wins
|
|
349
|
+
def my_func(): ...
|
|
350
|
+
```
|
|
351
|
+
|
|
144
352
|
## Roadmap
|
|
145
353
|
|
|
146
354
|
### Observability & Debugging
|
|
@@ -196,7 +404,6 @@ results = process_large_dataset(items)
|
|
|
196
404
|
- Log analysis utilities
|
|
197
405
|
- Telemetry visualization
|
|
198
406
|
|
|
199
|
-
|
|
200
407
|
### Enterprise Features
|
|
201
408
|
- **Integration**
|
|
202
409
|
- Distributed tracing (OpenTelemetry)
|
|
@@ -241,61 +448,4 @@ Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTIN
|
|
|
241
448
|
|
|
242
449
|
## License
|
|
243
450
|
|
|
244
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
245
|
-
|
|
246
|
-
## Configuration
|
|
247
|
-
|
|
248
|
-
Pyarallel provides a flexible configuration system that allows you to customize its behavior globally or per-function:
|
|
249
|
-
|
|
250
|
-
### Basic Configuration
|
|
251
|
-
|
|
252
|
-
```python
|
|
253
|
-
from pyarallel import ConfigManager
|
|
254
|
-
|
|
255
|
-
# Get the global configuration manager
|
|
256
|
-
config = ConfigManager.get_instance()
|
|
257
|
-
|
|
258
|
-
# Update configuration
|
|
259
|
-
config.update_config({
|
|
260
|
-
"max_workers": 8,
|
|
261
|
-
"timeout": 60.0,
|
|
262
|
-
"debug": True
|
|
263
|
-
})
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### Configuration Options
|
|
267
|
-
|
|
268
|
-
- **Execution Settings**
|
|
269
|
-
- `max_workers`: Maximum number of worker processes/threads (default: 4)
|
|
270
|
-
- `timeout`: Default timeout for parallel operations in seconds (default: 30.0)
|
|
271
|
-
|
|
272
|
-
- **Resource Management**
|
|
273
|
-
- `memory_limit`: Memory limit per worker in bytes (default: None)
|
|
274
|
-
- `cpu_affinity`: Enable CPU affinity for workers (default: False)
|
|
275
|
-
|
|
276
|
-
- **Logging and Debugging**
|
|
277
|
-
- `debug`: Enable debug mode (default: False)
|
|
278
|
-
- `log_level`: Logging level (default: "INFO")
|
|
279
|
-
|
|
280
|
-
### Environment Variables
|
|
281
|
-
|
|
282
|
-
You can configure Pyarallel using environment variables with the `PYARALLEL_` prefix:
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
PYARALLEL_MAX_WORKERS=4
|
|
286
|
-
PYARALLEL_TIMEOUT=60.0
|
|
287
|
-
PYARALLEL_DEBUG=true
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### Configuration Files
|
|
291
|
-
|
|
292
|
-
Load configuration from JSON, YAML, or TOML files:
|
|
293
|
-
|
|
294
|
-
```python
|
|
295
|
-
from pyarallel import PyarallelConfig
|
|
296
|
-
|
|
297
|
-
# Load from file
|
|
298
|
-
config = PyarallelConfig.from_file("pyarallel.yaml")
|
|
299
|
-
|
|
300
|
-
# Convert to dictionary
|
|
301
|
-
config_dict = config.to_dict()
|
|
451
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|