A library for lazy evaluation with context caching
Project description
lazily
A Python library for lazy evaluation with context caching.
Installation
pip install lazily
Example usage
from lazily import cell, slot
@cell
def name(ctx: dict) -> str:
return "World"
@slot
def greeting(ctx: dict) -> str:
print("Calculating greeting...")
return f"Hello, {name(ctx).value}!"
@cell
def response(ctx: dict) -> str:
return "How are you?"
@slot
def greeting_and_response(ctx: dict) -> str:
print("Calculating greeting_and_response...")
return f"{greeting(ctx)} {response(ctx).value}"
ctx = {}
# First access: runs the function
greeting(ctx)
# Calculating greeting...
# 'Hello, World!'
# Second access: uses cache (no print)
greeting(ctx)
# 'Hello, World!'
# Dependencies also access cached values
greeting_and_response(ctx)
# Calculating greeting_and_response...
# 'Hello, World! How are you?'
# Dependencies also also cached
greeting_and_response(ctx)
# 'Hello, World! How are you?'
# Update cell: invalidates cache
name(ctx).value = "Lazily"
# Access again: re-runs the function
greeting_and_response(ctx)
# Calculating greeting_and_response...
# Calculating greeting...
# 'Hello, Lazily! How are you?'
# Another access: uses cache
greeting_and_response(ctx)
# 'Hello, Lazily! How are you?'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lazily-0.5.0.tar.gz
(16.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
lazily-0.5.0-py3-none-any.whl
(12.8 kB
view details)
File details
Details for the file lazily-0.5.0.tar.gz.
File metadata
- Download URL: lazily-0.5.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6395e682473534b8345fd5dc062eac20ca42d2542894a078f1f9fab68de2e88
|
|
| MD5 |
bb01efc7b9605a65b3c62cadf26f6c7f
|
|
| BLAKE2b-256 |
ef8d2b26b2681d19230508b2bea700923291cf822a902d8e577aefb5f0904e7e
|
File details
Details for the file lazily-0.5.0-py3-none-any.whl.
File metadata
- Download URL: lazily-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad88d3a5ea5de7a697aca1b1305717b7cb6ff141b61d3984f1f0508b5f03edc1
|
|
| MD5 |
ce3a576bed76ce60ec969d3b03b5aa1d
|
|
| BLAKE2b-256 |
5e7a4ed7121f87db9215373bcb52f182333d533b01110f545c8ed9de707fc08e
|