Skip to main content

CBL – CodeBasedLearning

A Python package for code-based learning: utilities to inspect your Python environment, a small typed IPO (Input/Process/Output) teaching framework, and helpers for demo scripts.

Description

The cbl package is an educational library. It is part of the codebasedlearning idea and serves as both a learning tool and a practical utility for educational purposes. It contains three subpackages:

  • cbl.setup — information about the package, the platform, and the Python interpreter (about_package, about_platform, about_python).
  • cbl.ipo — a minimal, fully typed IPO/EVA pipeline framework with a four-role data model and composable producers/processors/consumers.
  • cbl.printing — console helpers for demo and teaching scripts.

Features

  • Zero external dependencies
  • Python 3.11+ compatible
  • Fully typed (PEP 561, py.typed)
  • Cross-platform support
  • Simple dataclass-based APIs
  • Educational and practical use cases

cbl.ipo in a nutshell

The framework separates a pipeline into four data roles —

read() -> I  ->  P.of(I)  ->  process(P) -> R  ->  O.of(I, P, R)  ->  write(O)

I  InputData    source-shaped, what was read
P  ProblemData  frozen statement of the problem
R  ResultData   the computed answer — exists only AFTER processing
O  OutputData   presentation-shaped, assembled from I, P and R

— and provides combinators to compose them: Tee (multiple consumers), Concat (union of producers), Refine (configuration layering), Stages (explicit accumulator pipeline), Parallel (strategy fan-out with reduce), plus a per-item error policy (on_error) for batch runs.

from dataclasses import dataclass
from typing import Iterator, Self

from cbl.ipo import IPO, Producer, Processor, Consumer


@dataclass(frozen=True)
class Spec:                      # InputData
    source: str
    x: int

@dataclass(frozen=True)
class Statement:                 # ProblemData
    x: int
    @classmethod
    def of(cls, input_data: Spec) -> Self:
        return cls(x=input_data.x)

@dataclass(frozen=True)
class Solution:                  # ResultData
    y: int

@dataclass(frozen=True)
class Result:                    # OutputData
    source: str
    y: int
    @classmethod
    def of(cls, input_data: Spec, problem: Statement, result: Solution) -> Self:
        return cls(source=input_data.source, y=result.y)


class SquareProblem(IPO[Spec, Statement, Solution, Result]):
    pass

class Numbers(Producer[Spec]):
    def read(self) -> Iterator[Spec]:
        yield Spec(source="demo", x=4)

class Square(Processor[Statement, Solution]):
    def process(self, problem: Statement) -> Solution:
        return Solution(y=problem.x ** 2)

class Console(Consumer[Result]):
    def write(self, output_data: Result) -> None:
        print(output_data)


SquareProblem.of(input=Numbers(), process=Square(), output=Console()).solve()

Worked examples — the step-by-step derivation of the pattern, composition recipes, and a CLI application shell — live in examples/ipo/ in this repository (not part of the installed package).

Installation

Use uv, pip or your IDE to install the package.

Development

  • uv sync installs the package (editable) plus the dev tools.
  • uv run pytest runs the tests.
  • uv run mypy type-checks the sources.
  • CI (GitHub Actions) runs both on Python 3.11 and 3.13 and smoke-runs the example scripts.

Build

  • Use uv build to build the package. You can find the built package in the dist folder.
  • Use uv publish to publish the package to PyPI with __token__ as the user name and an access token from PyPI.

Changelog

See CHANGELOG.md. Note for 2.0.0: requires-python moved from >=3.9 to >=3.11.

Release files for cbl 2.0.0

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

Source distribution (sdist)

Source distribution for cbl 2.0.0
File Size Uploaded
cbl-2.0.0.tar.gz 20.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cbl 2.0.0
File Interpreter ABI Platform
cbl-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.0 kB

Release files / cbl-2.0.0.tar.gz

Download URL cbl-2.0.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
84fd576bffc13fc0542cb8aba750271788b115cb0d002ac89aaa72199416a7f3
BLAKE2b-256 checksum
How to use checksums
27adf246703901e2b240634867b2874e17488cc7de5d946bde752bd95c10a237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / cbl-2.0.0-py3-none-any.whl

Download URL cbl-2.0.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a91a228cf7107ff2e308303cb6ed11e8f9d4e5945daf33c95bb07fca7a48b2a2
BLAKE2b-256 checksum
How to use checksums
d663fc1d1d34007283990be893a3d4487d87e44e7763dcf3ebdba37d3591b046
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

2.1.0

2 release files

This release

2.0.0 This release

2 release files

0.4.2

2 release files

0.2.3

2 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