pyarallel 0.1.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.
@@ -0,0 +1,43 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual Environment
24
+ venv/
25
+ env/
26
+ ENV/
27
+ .venv
28
+
29
+ # IDE
30
+ .idea/
31
+ .vscode/
32
+ *.swp
33
+ *.swo
34
+
35
+ # Test
36
+ .coverage
37
+ htmlcov/
38
+ .pytest_cache/
39
+ .tox/
40
+
41
+ # Misc
42
+ .DS_Store
43
+ *.log
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,56 @@
1
+ # Contributing to Pyarallel
2
+
3
+ We love your input! We want to make contributing to Pyarallel as easy and transparent as possible, whether it's:
4
+
5
+ - Reporting a bug
6
+ - Discussing the current state of the code
7
+ - Submitting a fix
8
+ - Proposing new features
9
+ - Becoming a maintainer
10
+
11
+ ## Development Process
12
+
13
+ We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.
14
+
15
+ 1. Fork the repo and create your branch from `main`.
16
+ 2. If you've added code that should be tested, add tests.
17
+ 3. If you've changed APIs, update the documentation.
18
+ 4. Ensure the test suite passes.
19
+ 5. Make sure your code lints.
20
+ 6. Issue that pull request!
21
+
22
+ ## Any Contributions You Make Will Be Under the MIT License
23
+ In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
24
+
25
+ ## Report Bugs Using GitHub's [Issue Tracker](https://github.com/oneryalcin/pyarallel/issues)
26
+
27
+ We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/oneryalcin/pyarallel/issues/new); it's that easy!
28
+
29
+ ## Write Bug Reports With Detail, Background, and Sample Code
30
+
31
+ **Great Bug Reports** tend to have:
32
+
33
+ - A quick summary and/or background
34
+ - Steps to reproduce
35
+ - Be specific!
36
+ - Give sample code if you can.
37
+ - What you expected would happen
38
+ - What actually happens
39
+ - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
40
+
41
+ ## Use a Consistent Coding Style
42
+
43
+ * Use [Black](https://github.com/psf/black) for Python code formatting
44
+ * Keep line length to 88 characters (Black default)
45
+ * Use type hints for function arguments and return values
46
+ * Write docstrings for all public functions and classes
47
+
48
+ ## Running Tests
49
+
50
+ ```bash
51
+ pytest tests/
52
+ ```
53
+
54
+ ## License
55
+
56
+ By contributing, you agree that your contributions will be licensed under its MIT License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pyarallel Contributors
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,283 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyarallel
3
+ Version: 0.1.0
4
+ Summary: A powerful parallel execution library for Python
5
+ Project-URL: Homepage, https://github.com/oneryalcin/pyarallel
6
+ Project-URL: Repository, https://github.com/oneryalcin/pyarallel.git
7
+ Project-URL: Documentation, https://github.com/oneryalcin/pyarallel
8
+ Author-email: Mehmet Oner Yalcin <oneryalcin@gmail.com>
9
+ License: MIT License
10
+
11
+ Copyright (c) 2025 Pyarallel Contributors
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE.md
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.12
36
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
37
+ Requires-Python: >=3.12
38
+ Description-Content-Type: text/markdown
39
+
40
+ # Pyarallel
41
+
42
+ A powerful,feature-rich parallel execution library for Python that makes concurrent programming easy and efficient.
43
+
44
+ ## Features
45
+
46
+ - **Simple Decorator-Based API**: Just add `@parallel` to your functions
47
+ - **Flexible Parallelism**: Choose between threads (I/O-bound) and processes (CPU-bound)
48
+ - **Smart Rate Limiting**: Control execution rates with per-second, per-minute, or per-hour limits
49
+ - **Batch Processing**: Handle large datasets efficiently with automatic batching
50
+ - **Performance Optimized**:
51
+ - Automatic worker pool reuse
52
+ - Optional worker prewarming for latency-critical applications
53
+ - Smart defaults based on your system
54
+ - **Production Ready**:
55
+ - Thread-safe implementation
56
+ - Memory-efficient with automatic cleanup
57
+ - Comprehensive error handling
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install pyarallel
63
+ ```
64
+
65
+ ## Quick Start
66
+
67
+ ```python
68
+ from pyarallel import parallel
69
+
70
+ # Basic parallel processing
71
+ @parallel(max_workers=4)
72
+ def fetch_url(url: str) -> dict:
73
+ return requests.get(url).json()
74
+
75
+ # Process multiple URLs in parallel
76
+ urls = ["http://api1.com", "http://api2.com"]
77
+ results = fetch_url(urls)
78
+
79
+ # Rate-limited CPU-intensive task
80
+ @parallel(
81
+ max_workers=4,
82
+ executor_type="process",
83
+ rate_limit=(100, "minute") # 100 ops/minute
84
+ )
85
+ def process_image(image: bytes) -> bytes:
86
+ return heavy_processing(image)
87
+
88
+ # Memory-efficient batch processing
89
+ @parallel(max_workers=4, batch_size=10)
90
+ def analyze_text(text: str) -> dict:
91
+ return text_analysis(text)
92
+ ```
93
+
94
+ ## Advanced Usage
95
+
96
+ ### Rate Limiting
97
+
98
+ Control execution rates using various formats:
99
+
100
+ ```python
101
+ # Operations per second
102
+ @parallel(rate_limit=2.0)
103
+ def func1(): ...
104
+
105
+ # Operations per minute
106
+ @parallel(rate_limit=(100, "minute"))
107
+ def func2(): ...
108
+
109
+ # Custom rate limit object
110
+ from pyarallel import RateLimit
111
+ rate = RateLimit(1000, "hour")
112
+ @parallel(rate_limit=rate)
113
+ def func3(): ...
114
+ ```
115
+
116
+ ### CPU-Bound Tasks
117
+
118
+ Use process-based parallelism for CPU-intensive operations:
119
+
120
+ ```python
121
+ @parallel(
122
+ max_workers=4,
123
+ executor_type="process", # Use processes instead of threads
124
+ batch_size=10 # Process in batches of 10
125
+ )
126
+ def cpu_intensive(data: bytes) -> bytes:
127
+ return heavy_computation(data)
128
+ ```
129
+
130
+ ### Latency-Critical Applications
131
+
132
+ Prewarm workers to minimize cold start latency:
133
+
134
+ ```python
135
+ @parallel(
136
+ max_workers=4,
137
+ prewarm=True # Start workers immediately
138
+ )
139
+ def latency_critical(item): ...
140
+ ```
141
+
142
+ ### Memory-Efficient Processing
143
+
144
+ Handle large datasets with batch processing:
145
+
146
+ ```python
147
+ @parallel(
148
+ max_workers=4,
149
+ batch_size=100 # Process items in batches of 100
150
+ )
151
+ def process_large_dataset(item): ...
152
+
153
+ # Process millions of items without memory issues
154
+ items = range(1_000_000)
155
+ results = process_large_dataset(items)
156
+ ```
157
+
158
+ ## Best Practices
159
+
160
+ 1. **Choose the Right Executor**:
161
+ - Use `executor_type="thread"` (default) for I/O-bound tasks (network, disk)
162
+ - Use `executor_type="process"` for CPU-bound tasks (computation)
163
+
164
+ 2. **Optimize Worker Count**:
165
+ - For I/O-bound: `max_workers = cpu_count * 5` (default)
166
+ - For CPU-bound: `max_workers = cpu_count` (default)
167
+
168
+ 3. **Control Resource Usage**:
169
+ - Use `batch_size` for large datasets
170
+ - Use `rate_limit` to prevent overwhelming resources
171
+ - Only use `prewarm=True` when cold start latency is critical
172
+
173
+ 4. **Handle Errors Properly**:
174
+ ```python
175
+ @parallel()
176
+ def my_func(item):
177
+ try:
178
+ return process(item)
179
+ except Exception as e:
180
+ return {"error": str(e), "item": item}
181
+ ```
182
+
183
+ ## Roadmap
184
+
185
+ ### Observability & Debugging
186
+ - **Advanced Telemetry System**
187
+ - Task execution metrics (duration, wait times, queue times)
188
+ - Worker utilization tracking
189
+ - Error frequency analysis
190
+ - SQLite persistence for historical data
191
+ - Interactive visualizations with Plotly
192
+ - Performance bottleneck identification
193
+
194
+ - **Rich Logging System**
195
+ - Configurable log levels per component
196
+ - Structured logging for machine parsing
197
+ - Contextual information for debugging
198
+ - Log rotation and management
199
+ - Integration with popular logging frameworks
200
+
201
+ ### Advanced Features
202
+ - **Callback System**
203
+ - Pre/post execution hooks
204
+ - Error handling callbacks
205
+ - Progress tracking
206
+ - Custom metrics collection
207
+ - State management hooks
208
+
209
+ - **Smart Scheduling**
210
+ - Priority queues for tasks
211
+ - Deadline-aware scheduling
212
+ - Resource-aware task distribution
213
+ - Adaptive batch sizing
214
+ - Dynamic worker scaling
215
+
216
+ - **Fault Tolerance**
217
+ - Automatic retries with backoff
218
+ - Circuit breaker pattern
219
+ - Fallback strategies
220
+ - Dead letter queues
221
+ - Task timeout handling
222
+
223
+ - **Resource Management**
224
+ - Memory usage monitoring
225
+ - CPU utilization tracking
226
+ - Network bandwidth control
227
+ - Disk I/O rate limiting
228
+ - Resource quotas per task
229
+
230
+ ### Developer Experience
231
+ - **CLI Tools**
232
+ - Task monitoring dashboard
233
+ - Performance profiling
234
+ - Configuration management
235
+ - Log analysis utilities
236
+ - Telemetry visualization
237
+
238
+
239
+ ### Enterprise Features
240
+ - **Integration**
241
+ - Distributed tracing (OpenTelemetry)
242
+ - Metrics export (Prometheus)
243
+ - Log aggregation (ELK Stack)
244
+
245
+ Want to contribute? Check out our [CONTRIBUTING.md](CONTRIBUTING.md) guide!
246
+
247
+ ## API Reference
248
+
249
+ ### @parallel Decorator
250
+
251
+ ```python
252
+ @parallel(
253
+ max_workers: int = None, # Maximum workers (default: based on CPU)
254
+ batch_size: int = None, # Items per batch (default: all at once)
255
+ rate_limit: Union[ # Rate limiting configuration
256
+ float, # - Operations per second
257
+ Tuple[float, str], # - (count, interval)
258
+ RateLimit # - RateLimit object
259
+ ] = None,
260
+ executor_type: str = "thread", # "thread" or "process"
261
+ prewarm: bool = False # Prewarm workers
262
+ )
263
+ ```
264
+
265
+ ### RateLimit Class
266
+
267
+ ```python
268
+ class RateLimit:
269
+ def __init__(self, count: float, interval: str = "second"):
270
+ """
271
+ Args:
272
+ count: Operations allowed per interval
273
+ interval: "second", "minute", or "hour"
274
+ """
275
+ ```
276
+
277
+ ## Contributing
278
+
279
+ Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTING.md).
280
+
281
+ ## License
282
+
283
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,244 @@
1
+ # Pyarallel
2
+
3
+ A powerful,feature-rich parallel execution library for Python that makes concurrent programming easy and efficient.
4
+
5
+ ## Features
6
+
7
+ - **Simple Decorator-Based API**: Just add `@parallel` to your functions
8
+ - **Flexible Parallelism**: Choose between threads (I/O-bound) and processes (CPU-bound)
9
+ - **Smart Rate Limiting**: Control execution rates with per-second, per-minute, or per-hour limits
10
+ - **Batch Processing**: Handle large datasets efficiently with automatic batching
11
+ - **Performance Optimized**:
12
+ - Automatic worker pool reuse
13
+ - Optional worker prewarming for latency-critical applications
14
+ - Smart defaults based on your system
15
+ - **Production Ready**:
16
+ - Thread-safe implementation
17
+ - Memory-efficient with automatic cleanup
18
+ - Comprehensive error handling
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install pyarallel
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```python
29
+ from pyarallel import parallel
30
+
31
+ # Basic parallel processing
32
+ @parallel(max_workers=4)
33
+ def fetch_url(url: str) -> dict:
34
+ return requests.get(url).json()
35
+
36
+ # Process multiple URLs in parallel
37
+ urls = ["http://api1.com", "http://api2.com"]
38
+ results = fetch_url(urls)
39
+
40
+ # Rate-limited CPU-intensive task
41
+ @parallel(
42
+ max_workers=4,
43
+ executor_type="process",
44
+ rate_limit=(100, "minute") # 100 ops/minute
45
+ )
46
+ def process_image(image: bytes) -> bytes:
47
+ return heavy_processing(image)
48
+
49
+ # Memory-efficient batch processing
50
+ @parallel(max_workers=4, batch_size=10)
51
+ def analyze_text(text: str) -> dict:
52
+ return text_analysis(text)
53
+ ```
54
+
55
+ ## Advanced Usage
56
+
57
+ ### Rate Limiting
58
+
59
+ Control execution rates using various formats:
60
+
61
+ ```python
62
+ # Operations per second
63
+ @parallel(rate_limit=2.0)
64
+ def func1(): ...
65
+
66
+ # Operations per minute
67
+ @parallel(rate_limit=(100, "minute"))
68
+ def func2(): ...
69
+
70
+ # Custom rate limit object
71
+ from pyarallel import RateLimit
72
+ rate = RateLimit(1000, "hour")
73
+ @parallel(rate_limit=rate)
74
+ def func3(): ...
75
+ ```
76
+
77
+ ### CPU-Bound Tasks
78
+
79
+ Use process-based parallelism for CPU-intensive operations:
80
+
81
+ ```python
82
+ @parallel(
83
+ max_workers=4,
84
+ executor_type="process", # Use processes instead of threads
85
+ batch_size=10 # Process in batches of 10
86
+ )
87
+ def cpu_intensive(data: bytes) -> bytes:
88
+ return heavy_computation(data)
89
+ ```
90
+
91
+ ### Latency-Critical Applications
92
+
93
+ Prewarm workers to minimize cold start latency:
94
+
95
+ ```python
96
+ @parallel(
97
+ max_workers=4,
98
+ prewarm=True # Start workers immediately
99
+ )
100
+ def latency_critical(item): ...
101
+ ```
102
+
103
+ ### Memory-Efficient Processing
104
+
105
+ Handle large datasets with batch processing:
106
+
107
+ ```python
108
+ @parallel(
109
+ max_workers=4,
110
+ batch_size=100 # Process items in batches of 100
111
+ )
112
+ def process_large_dataset(item): ...
113
+
114
+ # Process millions of items without memory issues
115
+ items = range(1_000_000)
116
+ results = process_large_dataset(items)
117
+ ```
118
+
119
+ ## Best Practices
120
+
121
+ 1. **Choose the Right Executor**:
122
+ - Use `executor_type="thread"` (default) for I/O-bound tasks (network, disk)
123
+ - Use `executor_type="process"` for CPU-bound tasks (computation)
124
+
125
+ 2. **Optimize Worker Count**:
126
+ - For I/O-bound: `max_workers = cpu_count * 5` (default)
127
+ - For CPU-bound: `max_workers = cpu_count` (default)
128
+
129
+ 3. **Control Resource Usage**:
130
+ - Use `batch_size` for large datasets
131
+ - Use `rate_limit` to prevent overwhelming resources
132
+ - Only use `prewarm=True` when cold start latency is critical
133
+
134
+ 4. **Handle Errors Properly**:
135
+ ```python
136
+ @parallel()
137
+ def my_func(item):
138
+ try:
139
+ return process(item)
140
+ except Exception as e:
141
+ return {"error": str(e), "item": item}
142
+ ```
143
+
144
+ ## Roadmap
145
+
146
+ ### Observability & Debugging
147
+ - **Advanced Telemetry System**
148
+ - Task execution metrics (duration, wait times, queue times)
149
+ - Worker utilization tracking
150
+ - Error frequency analysis
151
+ - SQLite persistence for historical data
152
+ - Interactive visualizations with Plotly
153
+ - Performance bottleneck identification
154
+
155
+ - **Rich Logging System**
156
+ - Configurable log levels per component
157
+ - Structured logging for machine parsing
158
+ - Contextual information for debugging
159
+ - Log rotation and management
160
+ - Integration with popular logging frameworks
161
+
162
+ ### Advanced Features
163
+ - **Callback System**
164
+ - Pre/post execution hooks
165
+ - Error handling callbacks
166
+ - Progress tracking
167
+ - Custom metrics collection
168
+ - State management hooks
169
+
170
+ - **Smart Scheduling**
171
+ - Priority queues for tasks
172
+ - Deadline-aware scheduling
173
+ - Resource-aware task distribution
174
+ - Adaptive batch sizing
175
+ - Dynamic worker scaling
176
+
177
+ - **Fault Tolerance**
178
+ - Automatic retries with backoff
179
+ - Circuit breaker pattern
180
+ - Fallback strategies
181
+ - Dead letter queues
182
+ - Task timeout handling
183
+
184
+ - **Resource Management**
185
+ - Memory usage monitoring
186
+ - CPU utilization tracking
187
+ - Network bandwidth control
188
+ - Disk I/O rate limiting
189
+ - Resource quotas per task
190
+
191
+ ### Developer Experience
192
+ - **CLI Tools**
193
+ - Task monitoring dashboard
194
+ - Performance profiling
195
+ - Configuration management
196
+ - Log analysis utilities
197
+ - Telemetry visualization
198
+
199
+
200
+ ### Enterprise Features
201
+ - **Integration**
202
+ - Distributed tracing (OpenTelemetry)
203
+ - Metrics export (Prometheus)
204
+ - Log aggregation (ELK Stack)
205
+
206
+ Want to contribute? Check out our [CONTRIBUTING.md](CONTRIBUTING.md) guide!
207
+
208
+ ## API Reference
209
+
210
+ ### @parallel Decorator
211
+
212
+ ```python
213
+ @parallel(
214
+ max_workers: int = None, # Maximum workers (default: based on CPU)
215
+ batch_size: int = None, # Items per batch (default: all at once)
216
+ rate_limit: Union[ # Rate limiting configuration
217
+ float, # - Operations per second
218
+ Tuple[float, str], # - (count, interval)
219
+ RateLimit # - RateLimit object
220
+ ] = None,
221
+ executor_type: str = "thread", # "thread" or "process"
222
+ prewarm: bool = False # Prewarm workers
223
+ )
224
+ ```
225
+
226
+ ### RateLimit Class
227
+
228
+ ```python
229
+ class RateLimit:
230
+ def __init__(self, count: float, interval: str = "second"):
231
+ """
232
+ Args:
233
+ count: Operations allowed per interval
234
+ interval: "second", "minute", or "hour"
235
+ """
236
+ ```
237
+
238
+ ## Contributing
239
+
240
+ Contributions are welcome! Please check out our [Contributing Guide](CONTRIBUTING.md).
241
+
242
+ ## License
243
+
244
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,6 @@
1
+ def main():
2
+ print("Hello from pyarallel!")
3
+
4
+
5
+ if __name__ == "__main__":
6
+ main()
@@ -0,0 +1,10 @@
1
+ from .core import parallel, RateLimit
2
+
3
+ __version__ = "0.1.0"
4
+ __all__ = ["parallel", "RateLimit"]
5
+
6
+ __doc__ = f"""
7
+ pyarallel v{__version__}
8
+
9
+ Simple parallel processing framework for Python.
10
+ """