Skip to main content

Encapsulation and decorators made easy.

Project description

The encapsulation library

Introducing: the From class.

Decorators made easy, piece-wise oprations on product types, controlling evaluation order.

For maintainable data pipelines.

It's a monad (sorry 🍪).

Installation

pip install -e encapsulation

Getting started

Get started by

from encapsulation.base import From

obj = From(
    lambda x: "hi " + x        
    )("there")

print(obj)

Easy decorator superpowers:

from encapsulation.base import From

def inspect(x: str): 
    """some function you want to call each time"""
    print(x)

def compose(func, *args):
    inspect(func)
    func(*args)

# you can also turn inspect into a proper decorator using
agent = From(Fn=compose).apply

@agent
def task(val: str):
    """Some task"""
    print("[this is a task]")

task("hiho")

The above will both evaluate task("hiho") and leave its return type untouched, while also executing agent(task) each time the task function gets called.

Congratulations! You can now stop writing convoluted wrappers each time you want to implement a decorator, and use From instead 😎

Project details


Download files

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

Source Distribution

encapsulation-0.1.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

encapsulation-0.1.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file encapsulation-0.1.3.tar.gz.

File metadata

  • Download URL: encapsulation-0.1.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for encapsulation-0.1.3.tar.gz
Algorithm Hash digest
SHA256 64a5e4e7e94fb3c6da4bb99d84c2754dec03a5d141bc75d5fdc817d0c2c80582
MD5 af81d189556fece57cd16a72fc89ded8
BLAKE2b-256 6041dacb632bad73106895b83d7cb9d5de3363a76ca92b3bf21600be4f92e6d2

See more details on using hashes here.

File details

Details for the file encapsulation-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: encapsulation-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for encapsulation-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0bdf5cc23a7cd541795c89e47911ad72d143a48ea4b8cf4616e9b0a7a885c10d
MD5 9b8e56f9d5641c6c72896ea99c4501aa
BLAKE2b-256 fad63a0928890a57aa325eca3caf0b09942e39fc778a5a8247f839d3ddcdc224

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page