Skip to main content

LOGO


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

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, str
  • list[...] of allowed types
  • dict[...] of allowed types (typically dict[str, ...])
  • nested combinations of the above
  • @Threadable classes
  • 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

  1. Typed parameters and a return type (use -> None when there is no value).
  2. No *args / **kwargs.
  3. Locals must be annotated with an allowed type (x: int = 0).
  4. Inside the body, only call other @Thread functions/methods, plus python math (import math), cthreads.modules, not arbitrary Python.
  5. 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

  1. All fields are typed at class scope (dataclass-style annotations).
  2. Do not define / override __init__. The decorator injects a dataclass-style constructor (ExampleClass(1, "x") or ExampleClass(attr1=1); omitted fields zero / empty, matching C++ T{}).
  3. Kernel methods must use @Thread and take self like normal methods.
  4. 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.


Metadata

Release files for cthreads 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cthreads 0.2.1
File Size Uploaded
cthreads-0.2.1.tar.gz 419.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for cthreads 0.2.1
File
cthreads-0.2.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
cthreads-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
cthreads-0.2.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
cthreads-0.2.1-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-0.2.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
cthreads-0.2.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
cthreads-0.2.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
cthreads-0.2.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details

Total release size: 11.0 MB

Release files / cthreads-0.2.1.tar.gz

Download URL cthreads-0.2.1.tar.gz
Size 419.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dbf27dcb6132cfe7602aaecfbe2c616c7843c73c05a48c8487154bbadb5b0769
BLAKE2b-256 checksum
How to use checksums
1b4a0806717a6fcf8b2cc8a9d72e452c73eb81e27dd62152d7678bc13f9381eb
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp313-cp313-win_amd64.whl

Download URL cthreads-0.2.1-cp313-cp313-win_amd64.whl
Size 1.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
d761d8bdd0f4026c324fe3524ef76d85b06696af5835be95b27aaa1100b06e6c
BLAKE2b-256 checksum
How to use checksums
2a9da23f78b031f2a8374f9561743929a45c2b49f86f8bfc787ddbfc5995f091
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cthreads-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.2 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f6efb6bacebd5f67b748b7c3563cd271d70f6eb721f2a176e0960414d26ac3eb
BLAKE2b-256 checksum
How to use checksums
1e7e96962654e1ae99e381326822b942e24269950d4d612f00b5a1df0833df06
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp312-cp312-win_amd64.whl

Download URL cthreads-0.2.1-cp312-cp312-win_amd64.whl
Size 1.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
f4dcf453490b7c4461f8d2ff5661716faaa0301cd03b4d1a17b9ab299ab0a61a
BLAKE2b-256 checksum
How to use checksums
24954b184b929e3b887d267c47b308c659deee7c27dc4c1c78e4c97eee426a39
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cthreads-0.2.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.7 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a7948b863e4719439fcc94250e96f1b2d98ff506363a94c7bea6c94c6012829c
BLAKE2b-256 checksum
How to use checksums
204eb73836f0f16f0fba1433f986164b113a4cd980a6c20c7b88040bc2e848b2
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp311-cp311-win_amd64.whl

Download URL cthreads-0.2.1-cp311-cp311-win_amd64.whl
Size 1.0 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
484a3a55cf283b401a7b75cf5a63599e156b2978f221e9331c1ccb32c9faa78c
BLAKE2b-256 checksum
How to use checksums
e65de49687a80ec3467dcaa1be1efdb6a58e5d5bc3dcf050bda3bcef95d4f8ba
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cthreads-0.2.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
52174b39cfc35af7d9069e61c6c544abb8d684c491777d4b8c1977148fbb6fd1
BLAKE2b-256 checksum
How to use checksums
1d54e2c40e05bad8521d9eb053e58814981691bee3bb0d322ef72754cbe2c92c
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp310-cp310-win_amd64.whl

Download URL cthreads-0.2.1-cp310-cp310-win_amd64.whl
Size 710.1 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
0afa079bb384c4e9723206f9cba548ac9f81f6a872468272a869ee6972fcc3bb
BLAKE2b-256 checksum
How to use checksums
137213b03df63bcbb6bf280deb8a1891a9ffb33abf252f8300d015fcfa559112
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 19, 2026.

Transparency log

Release files / cthreads-0.2.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cthreads-0.2.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 698.0 kB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
cd83001183f42cb7d132596dcf9a55e80fb7faef0b8e7390d0a74f38fd927060
BLAKE2b-256 checksum
How to use checksums
6d2565b0f29172c42604d5e3f176b53a93d745c45d9ea174ee8d073ac063fc2f
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 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

9 release files

0.2.0

9 release files

0.1.1

9 release files

0.1.0

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page