Stpr

A structured concurrency library for Python

Concurrency
made easy.

Stpr lets you write concurrent pipelines with simple constructs - no callbacks, no thread juggling, no asyncio boilerplate.

install pip install stpr
import stpr

# Two code blocks run concurrently
with parallel:
with seq: # block A validate(data) transform(data) store(data)
with seq: # block B fetch_meta() with parallel: # nested parallelism index() notify() audit_log()

Features

The right tools for writing concurrent programs

A concise API that gives you composable concurrency primitives.

Composition

Code structure is execution structure

Nesting parallel inside seq inside parallel works exactly as it reads. The execution graph is derived directly from the code structure.

Easy Migration

Decorator-based adoption

Add @stpr.fn to any existing function to make it asynchronous and enable all Stpr features. No need to change the function body. Stpr will use the existing synchronous functions and switch to using await automatically when they are made async.

Performance

Scalable async I/O

Thousands of concurrent network calls, file reads, and DB queries on a single thread using asyncio event loops without the complexity of asyncio.

Safety

Structured error handling

Concurrent primitives use structure exception handling semantics in which errors propagate cleanly through context manager scopes.

Installation

Up and running in seconds

Requires Python 3.8 or later. Minimal external dependencies.

Full install guide →

PyPI — recommended

$ pip install stpr

From source

$ git clone https://github.com/hategan/stpr
$ pip install -e ./stpr

Verify

$ python -c 'import stpr; print(stpr.__version__)'