Skip to main content

pyUoW

Unit of Work for Python — composable units, transactional work managers, and a domain model toolkit.

📖 Read the docs  ·  Quickstart  ·  PyPI

Downloads Build Codecov Ruff Python versions License


What is PyUoW?

PyUoW is a Python implementation of the Unit of Work behavioural pattern. It gives you small, typed building blocks for business logic that compose into a flow and run inside a Work Manager that handles transactions, batching, and domain events.

The result: business logic that reads top-to-bottom, separates orchestration from execution, and stays testable as it grows.

Highlights

  • Composable units — write each step as a ConditionalUnit / RunUnit / FinalUnit, chain them with >>, validate the chain at build time.
  • Transactional out of the box — a SQLAlchemy adapter ships in pyuow.contrib.sqlalchemy (sync + async), with nested-transaction support.
  • Domain-firstEntity, AuditedEntity, SoftDeletableEntity, VersionedEntity, and an event-emitting Model base, all immutable dataclasses.
  • Sync and async parity — every primitive has an aio/ twin; pick one per flow.
  • Strict types — passes mypy --strict; runs on Python 3.10 through 3.14.

Install

pip install pyuow                # core
pip install "pyuow[sqlalchemy]"  # with SQLAlchemy integration

Python ≥ 3.10.

AI-agent skill

After installing, run pyuow install-skill to drop an AI-agent skill file into your project so Claude Code / OpenCode learn PyUoW's idioms. Add --global to install for your user account, or --check to dry-run.

See the step-by-step guide (or docs/install-skill.md).

At a glance

from dataclasses import dataclass

from pyuow import (
    BaseContext, BaseParams, ConditionalUnit, ErrorUnit,
    FinalUnit, Result, RunUnit,
)
from pyuow.work.noop import NoOpWorkManager


@dataclass(frozen=True)
class Greeting(BaseParams):
    name: str


@dataclass
class Ctx(BaseContext[Greeting]):
    params: Greeting


class IsNamePresent(ConditionalUnit[Ctx, str]):
    def condition(self, ctx: Ctx) -> bool:
        return bool(ctx.params.name)


class Greet(RunUnit[Ctx, str]):
    def run(self, ctx: Ctx) -> None:
        print(f"Hello, {ctx.params.name}!")


class Done(FinalUnit[Ctx, str]):
    def finish(self, ctx: Ctx) -> Result[str]:
        return Result.ok("greeted")


flow = (
    IsNamePresent(on_failure=ErrorUnit(exc=ValueError("name required")))
    >> Greet()
    >> Done()
).build()

result = NoOpWorkManager().by(flow).do_with(Ctx(params=Greeting(name="Alice")))
assert result.get() == "greeted"

What's in the box

Concept What it gives you
Units & Flow ConditionalUnit / RunUnit / FinalUnit / ErrorUnit, chained with >>
Result ok / error / empty plus .map, .and_then, .unwrap_or
Context Mutable, immutable, and domain-aware context bases
Work Manager NoOp, transactional, and domain-transactional managers
Domain Model Entity, AuditedEntity, Model, Batch, events, typed exceptions
DataPoints Typed producer / consumer contracts between units
SQLAlchemy Ready-made repositories, table mixins, and transaction manager
Async A sync and an aio/ twin for every primitive

Contributing

PRs welcome — see CONTRIBUTING.md for the dev setup, or run:

poetry install --with docs
make tests        # pytest + coverage
make fmt          # ruff + mypy
make docs-serve   # live preview at http://127.0.0.1:8000

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyuow-0.10.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyuow-0.10.0-py3-none-any.whl (55.7 kB view details)

Uploaded Python 3

File details

Details for the file pyuow-0.10.0.tar.gz.

File metadata

  • Download URL: pyuow-0.10.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure

File hashes

Hashes for pyuow-0.10.0.tar.gz
Algorithm Hash digest
SHA256 76044ff15a8c9b44f8426c448dfbcf07bb138802e6277ffa726c13016bd207ed
MD5 6c39960a344463a12fa32e4c7f50c574
BLAKE2b-256 c46105f716ac383734e2013b8fb621584216d6a28316cc845a2e79b4a2bb4b7f

See more details on using hashes here.

File details

Details for the file pyuow-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: pyuow-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 55.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1020-azure

File hashes

Hashes for pyuow-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adca50309ef0b01b25258e821b28be46b3ac2da9ac533ca43bf0b42b8cf9514b
MD5 d011a69dd337a322ebc31fcf00526ef9
BLAKE2b-256 332449b2a3e4258d2452f1657584960e15c77cf19ba3fa5bc6e8e51848d0a278

See more details on using hashes here.

Release history Release notifications | RSS feed

0.11.1

2 files

0.11.0

2 files

This release

0.10.0 This release

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.7

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.1

2 files

0.1.0

2 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