potiklib
Українська версія (README.uk.md)
potiklib is a zero-dependency Python 3.15+ library that gives you a clean, transparent developer experience for parallel CPU and asyncio execution on both free-threaded (No GIL) and GIL-enabled Python builds.
Installation
uv add potiklib
uv pip install potiklib
Quick Start
import asyncio
from potiklib import apotik, potik, run, task
@task
def cpu_square(x: int) -> int:
return x * x
def cpu_cube(x: int) -> int:
return x * x * x
async def main() -> None:
squares = await asyncio.gather(*(apotik(cpu_square, i) for i in range(4)))
cubes = potik(cpu_cube, 3)
print("squares:", squares, "cube(3):", cubes)
if __name__ == "__main__":
run(main)
Usage Examples
Parallel async def Tasks (@task + asyncio.gather)
import asyncio
from potiklib import run, task
@task
async def async_cpu_work(n: int) -> int:
await asyncio.sleep(0)
total = 0
for i in range(n):
total = (total + i * i) % 1_000_000_007
return total
async def main() -> list[int]:
return await asyncio.gather(*(async_cpu_work(2_000_000) for _ in range(4)))
if __name__ == "__main__":
print(run(main, workers=4))
Synchronous def Functions (potik & apotik)
import asyncio
from potiklib import apotik, potik, run
def compute_sum(limit: int) -> int:
total = 0
for i in range(limit):
total += i
return total
def sync_entry() -> int:
return potik(compute_sum, 1_000_000)
async def async_entry() -> list[int]:
return await asyncio.gather(
apotik(compute_sum, 1_000_000),
apotik(compute_sum, 2_000_000),
)
if __name__ == "__main__":
print("sync:", run(sync_entry, workers=2))
print("async:", run(async_entry, workers=2))
API Reference
| Symbol | Inside run() |
Outside run() (fallback) |
|---|---|---|
run(main, *, workers=None) |
Starts the runtime (workers defaults to os.process_cpu_count() or 1), runs def, async def, coroutine, or Awaitable, and shuts down initialized pools in finally. |
— |
@task on async def |
Runs in a worker thread's event loop (ATPE) with Least-Loaded balancing and contextvars propagation. |
Awaits fn(*args, **kwargs) in the caller's event loop. |
@task on def |
Runs in TPE (No GIL) or IPE (GIL) and returns the result. |
Calls fn(*args, **kwargs) directly. |
potik(fn, /, *args, **kwargs) |
Runs synchronous fn in TPE or IPE and waits for the result (with anti-deadlock fallback when no free threads remain). |
Calls fn(*args, **kwargs) directly. |
await apotik(target, /, *args, **kwargs) |
Routes Awaitable / async def to ATPE, and synchronous def to TPE / IPE. |
Awaits target / target(*args, **kwargs) or calls synchronous target directly. |
No GIL vs GIL Routing
At runtime, potiklib checks sys._is_gil_enabled() for synchronous tasks and lazily initializes only the pools actually used:
- Asynchronous tasks (
async def,Awaitable): Always routed toATPEProvider(aThreadPoolExecutorwhere each worker owns anasyncioevent loop). - Synchronous tasks with No GIL (
sys._is_gil_enabled() == False): Routed toTPEProvider(ThreadPoolExecutorwithcontextvarscopying andLock-tracked anti-deadlock detection). - Synchronous tasks with GIL enabled (
sys._is_gil_enabled() == True): Routed toIPEProvider(concurrent.futures.InterpreterPoolExecutor) so CPU-bound work runs in parallel across subinterpreters.
Note: When the GIL is enabled (
sys._is_gil_enabled() == True), synchronous functions executed viaInterpreterPoolExecutormust be picklable / cross-interpreter shareable at module top level: avoidlambda, local closures, default arguments that prevent sharing, or module-global references.@taskpreservesfunctools.wraps(fn)sopotiklibcan safely unwrap its own task decorator without stripping your custom decorators.
License
MIT License — see LICENSE.txt.
Metadata
Release files for potiklib 1.0.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 |
|---|---|---|---|---|
| potiklib-1.0.0.tar.gz | 8.2 kB | With provenance | Details for potiklib-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| potiklib-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for potiklib-1.0.0-py3-none-any.whl |
Total release size: 19.6 kB
Release files / potiklib-1.0.0.tar.gz
| Download URL | potiklib-1.0.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6176760684c488d368bf51a08c453e1f9cef0b574a2dce1e1b177b42f4569125
|
|
BLAKE2b-256 checksum How to use checksums |
1b9022c4acb3307c13a2a34f446aa79dc6906bb7b651b5eec6bd66171cfd4757
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / potiklib-1.0.0-py3-none-any.whl
| Download URL | potiklib-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80a06d31821b85443e56339acc90b45cf97d597381ec2051c8d0079b2a0751be
|
|
BLAKE2b-256 checksum How to use checksums |
3a10e2768a336d9831758e14f9e9e9bdef542f0c4f999b71da889ba5fe787ca9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for potiklib 1.0.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for potiklib-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA 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.