Skip to main content

Affection

Algebraic Effect for modern Python.

Tips: I strongly recommend you to read Algebraic Effects for the Rest of Us before you start.

Affection is a small library that implements Algebraic Effect for Python. It leverages asyncio, decorator and with syntax for a smooth experience.

Warning: Please note that until Higher Rank Type Variants are supported in Python, the Effect.handle API will be quite ugly.

Usage

This project is designed to be a single file project.

You can either directly copy it into your project, or add affection from PyPI with your favorite package manager.

from affection import Effect, Handle, effect, perform


class Log(Effect[None]):
    def __init__(self, content: str):
        self.content = content


def get_name(name: str | None = None) -> str:
    perform(Log(f"Getting name with {name}"))
    return perform(effect("ask_name", str)) if name is None else name


def main():
    with Handle() as h:

        @Log.handle(h)
        def _(l: Log):
            print(l.content)

        @effect("ask_name", str).handle(h)
        def _(_) -> str:
            return "Default"

        perform(Log("Test parent log"))

        with Handle() as i_h:
            @Log.handle(h)
            def _(l: Log):
                print("Inner", l.content.lower())
            print(get_name("Ann"))
            print(get_name())

if __name__ == "__main__":
    main()
    """
    Test parent log
    Inner getting name with ann
    Ann
    Inner getting name with none
    Default
    """

Metadata

Release files for affection 0.1.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 affection 0.1.1
File Size Uploaded Provenance Actions
affection-0.1.1.tar.gz 3.6 kB Without provenance Details for affection-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 7.4 kB

Release files / affection-0.1.1.tar.gz

Download URL affection-0.1.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4708fe734bfb78c2c9cb186c51422da9c5714614f32b3327f62f2e6a18ecf5c1
BLAKE2b-256 checksum
How to use checksums
0c929503c4a73cddcbbd6a3c07776cdd60e2c402869122edd1d285eddda57fb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.0.1 CPython/3.9.6

Release files / affection-0.1.1-py3-none-any.whl

Download URL affection-0.1.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
926cbaf37b861dd67c261defd52c378d845d0544e8f19e6decbe3ab5bd85c19e
BLAKE2b-256 checksum
How to use checksums
324396733f5b44c1343b2d12c9d5d1cfd83f1d2ba267af017412c8f5caed228b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.0.1 CPython/3.9.6

Security for affection 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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