hpylib
hpylib is a small Python library that provides simple building blocks for parallel programming with threads. It is designed to make it easy to run tasks asynchronously, coordinate them, and perform parallel map operations, all with minimal boilerplate.
It provides three main functions:
spawn(fn)— run a function asynchronously in a worker thread.finish()— context manager to wait for all asynchronous tasks submitted inside its block.pmap(fn, iterable)— parallel map: apply a function to each element of an iterable in parallel, returning the results as a list.
Installation
pip install hpylib
Usage
1. Asynchronous Tasks with spawn and finish
from hpylib import spawn, finish
import time
def work(x):
time.sleep(1)
print(f"Processed {x}")
with finish():
for i in range(5):
spawn(lambda i=i: work(i))
print("All tasks completed!")
-
spawn(fn) submits a task to run in the background.
-
finish() waits for all tasks submitted inside its block to complete.
2. Parallel Map with pmap
from hpylib import pmap
from math import isqrt
def is_prime(n):
if n < 2:
return False
for i in range(2, isqrt(n)+1):
if n % i == 0:
return False
return True
numbers = range(1, 100_000)
results = pmap(is_prime, numbers)
total_primes = sum(results)
print(f"Number of primes: {total_primes}")
-
pmap(fn, iterable) automatically splits the iterable into chunks and distributes the work across the thread pool.
-
Returns a list of results in the same order as the input.
-
Blocks until all tasks are complete.
Metadata
Release files for hpylib 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hpylib-0.1.0.tar.gz | 3.5 kB | Without provenance | Details for hpylib-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hpylib-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hpylib-0.1.0-py3-none-any.whl |
Total release size: 7.2 kB
Release files / hpylib-0.1.0.tar.gz
| Download URL | hpylib-0.1.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68ff55ea3083ef0b915345a3965773e63cab234d057e05d2d4c5069826a4a0e7
|
|
BLAKE2b-256 checksum How to use checksums |
f159f7597813d52a63c7e44cfb00000bbac21760ad97b7c396a55e68348b9d03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / hpylib-0.1.0-py3-none-any.whl
| Download URL | hpylib-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d8147631f8b4e2be614cb25319849a42aed64e3215a8f08cf2139e60bd9b90b
|
|
BLAKE2b-256 checksum How to use checksums |
cc35b904216674d121d7737940085ac19e28bf1bad134d14588eae24f438ec29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for hpylib 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.