cthreads compiles a typed Python subset into C++ so work can run on real OS threads without the GIL allowing true concurrency without multiprocessing's process boundaries and pickling tax.
Use @Thread on functions/methods and @Threadable on classes. The whitelist covers the usual scalars and containers, plus your own Threadable types. Code runs at native speed while you keep a Python-shaped control flow (jobs, pools, sync).
Docs
- Install (includes GPU / Vulkan notes)
- Guides
- GPU guides (0.2.0)
- Release (GitHub / PyPI)
- Math & linalg
- Compiler notes
- Sync / state writeback
- API reference
Install
Python >= 3.10, a C++17 compiler, and CMake >= 3.18 (CMake is only needed to build the native _ext module). Full toolchain notes: docs/install.md.
From PyPI
Published wheels (Linux / Windows x86_64) and the sdist are on PyPI:
pip install cthreads
# Vulkan GPU (@Gpu) support (full package; do not install alongside cthreads):
pip install cthreads-gpu
You still need a C++ compiler for the first thread(...) (user kernels). On Linux, wheels include a prebuilt _ext; CMake is only required if you install from the sdist or develop from source.
From this repo (editable)
python -m venv .venv
# activate, then:
pip install cmake ninja # CMake/Ninja in the venv; compiler is still system/MSVC
pip install -e ".[test]" # or: pip install -e .
First cthreads.thread(...) auto-runs cache-checked prepare + load_kernels. Call unload_kernels() before a force rebuild (thread(..., force=True) or prepare(force=True)).
How we publish: docs/release.md.
Introduction
Annotate what should become a native kernel:
@Thread- functions / methods compiled to C++@Threadable- classes compiled to C++ structs (shared state across kernels)@Gpu- functions compiled to Vulkan compute (lists of scalars; see GPU guides)
Supported types
Allowed in annotations (arguments, returns, locals, Threadable fields):
int,float,bool,strlist[...]of allowed typesdict[...]of allowed types (typicallydict[str, ...])- nested combinations of the above
@Threadableclasses- any internal types imported by
cthreads
This is a whitelist, not full Python. No arbitrary objects, no untyped values in kernels.
@Thread
Marks a function or method for compilation. Pass it to cthreads.thread(...) to run off the GIL.
from cthreads import Thread
@Thread
def my_example_function() -> None:
return None
Rules
- Typed parameters and a return type (use
-> Nonewhen there is no value). - No
*args/**kwargs. - Locals must be annotated with an allowed type (
x: int = 0). - Inside the body, only call other
@Threadfunctions/methods, pluspython math (import math),cthreads.modules, not arbitrary Python. - Return values must match the declared return type.
from cthreads import Thread
@Thread
def example_function(val1: int, val2: list[float], val3: ExampleClass) -> ExampleClass:
var4: str = "hello there"
var5: int = 42
val3.some_string_attr = var4
val3.some_int_attr = var5
return val3
@Threadable
Python's open object model does not map cleanly to C++. @Threadable marks a class so the compiler can emit a fixed C++ struct and marshal it safely.
from cthreads import Threadable
@Threadable
class MyExample:
x: float
y: float
Rules
- All fields are typed at class scope (dataclass-style annotations).
- Do not define / override
__init__. The decorator injects a dataclass-style constructor (ExampleClass(1, "x")orExampleClass(attr1=1); omitted fields zero / empty, matching C++T{}). - Kernel methods must use
@Threadand takeselflike normal methods. - Method argument / return annotations must be allowed types (or
-> None).
from cthreads import Threadable, Thread
@Threadable
class ExampleClass:
attr1: int
attr2: str
attr3: list[float]
@Thread
def method1(self) -> None:
self.attr1 += 1
@Thread
def method2(self, string: str) -> str:
return self.attr2 + string
obj = ExampleClass(0, "1", [2.0, 3.0])
obj.method1()
print(obj.attr1, obj.method2(" 1")) # 1 1 1
Why Threadables?
- shared state for worker threads
- typed containers / domain objects
- grouping related kernel methods
Run a @Thread
import cthreads
from cthreads import Thread
@Thread
def example_function(lhs: float, rhs: float, count: int) -> float:
for i in range(count):
lhs += rhs
return lhs
# Sync: Job -> join -> result
job = cthreads.thread(example_function, 1.5, 2.0, 200)
job.join() # starts if needed; blocks this thread (GIL released in C++)
result = job.result()
# Async: await auto-starts and returns the result (event loop stays free)
job = cthreads.thread(example_function, 1.5, 2.0, 200)
result = await job
Signature: cthreads.thread(fn, *args, force: bool = False, **kwargs) -> Job.
GPU (@Gpu, from 0.2.0)
Vulkan compute kernels use the same "annotate then launch" idea on a separate backend:
from cthreads.gpu import Gpu, GlobalIdx, gpu
@Gpu
def saxpy(n: int, a: float, x: list[float], y: list[float]) -> None:
i: int = GlobalIdx.x
if i >= n:
return
y[i] = a * x[i] + y[i]
x = [1.0, 2.0, 3.0, 4.0]
y = [10.0, 20.0, 30.0, 40.0]
gpu(saxpy, len(x), 2.0, x, y).join()
Full guides (concepts, best practices, examples): docs/guide/gpu/README.md. Install / drivers: docs/install.md.
Release files for cthreads-gpu 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| cthreads_gpu-0.2.0-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details |
| cthreads_gpu-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| cthreads_gpu-0.2.0-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| cthreads_gpu-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details |
| cthreads_gpu-0.2.0-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details |
| cthreads_gpu-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| cthreads_gpu-0.2.0-cp310-cp310-win_amd64.whl | CPython 3.10 | CPython 3.10 | Windows x86-64 | Details |
| cthreads_gpu-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
Total release size: 28.3 MB
Release files / cthreads_gpu-0.2.0-cp313-cp313-win_amd64.whl
| Download URL | cthreads_gpu-0.2.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a06f9f30013ad3bfa2f094a57255bae93f01cd67a5c1e8f834fb35823c27b9b3
|
|
BLAKE2b-256 checksum How to use checksums |
7ed34c874f4f221bb680aad27a109db7dc14a5e3987bbf4e4538360bca955d7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cthreads_gpu-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
4b45b2d76bccdef860c131a83abfa5f72eb78a577a36231d69a22981f87ce351
|
|
BLAKE2b-256 checksum How to use checksums |
e36a4fa36801bbab4688af5416f0880628a036553b84e22492b04764f3b75a9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp312-cp312-win_amd64.whl
| Download URL | cthreads_gpu-0.2.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
903c3289504b2406f5fdfa4b370a8b64f7dd3196bb97c1698a3168fc37789d55
|
|
BLAKE2b-256 checksum How to use checksums |
34f2c8066ab9c6f8a01cce6ff686143acfd9fad35c2a7eca7f4eb67409435e38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cthreads_gpu-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
03b3cc830332f991d18bcd79f9bf4091dc5c6acceffdb076a6c418b2c1224a47
|
|
BLAKE2b-256 checksum How to use checksums |
2979c2502cb9a3c6488f740900b3a57bb55239f8a92887a749c556725bbe1fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp311-cp311-win_amd64.whl
| Download URL | cthreads_gpu-0.2.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
50c4996e9e69bef3ff89f2c7a5aa6ae0fdce36c53514f17f87a8abdfcb7c84ad
|
|
BLAKE2b-256 checksum How to use checksums |
cf0bfed36d8c7f8d9a77a3186f6abbc62ffb35b5b89572efebe5c3e8d7f09a5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cthreads_gpu-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
bd4725ee2d8f913cdad141cd0d9b10c7bfd30142a1aaad2ea671866ab0f401ef
|
|
BLAKE2b-256 checksum How to use checksums |
60a03aea1be5aad3394ef5a883d92cc5f83fdbe98c5ed702f823b5a29f61de44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp310-cp310-win_amd64.whl
| Download URL | cthreads_gpu-0.2.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0a13b73446bde186f6ddbcee46f6a40e66acca42ff0c3c7b4193a9a5e9d9bf7e
|
|
BLAKE2b-256 checksum How to use checksums |
f1f4aaeef63008678ddb0e306001091b024b0546fcacd0b15b1d0dc6d810a2e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency logRelease files / cthreads_gpu-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cthreads_gpu-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
0e34d5abaadb7370f2418bec8f3b4be6ec94e2267a937a1513fc593844920a9e
|
|
BLAKE2b-256 checksum How to use checksums |
574b5afeb05cc0a9673cae8fc04b3d25dfe14f10b771a42277f7768b7f8be180
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 18, 2026.
Transparency log