Skip to main content

Python method chaining and piping with asyncio support.

Project description

DotChain - Python method chaining and piping with asyncio support.

Install

pip install dotchain

Usage

Chain Synchronously

Call .Result() to get the value.

value = DotChain(data | iterable).method().property.Result()

Chain Asynchronously

Do not call .Result() when using await.

value = await DotChain(data | iterable).method().property

NOTE: Must be in an event loop to use await.

Piping

Pipe can be called anywhere in the chain to start piping the data.

Chain can be called anywhere in the chain to start chaining the data again.

# Piping
value = DotChain(data | iterable).Pipe.method().other_method().Result()

# Chaining and Piping
value = DotChain(data | iterable).method().property.Pipe.other_method().Chain.property.Result()

Contexts

Contexts can be provided to resolve methods and properties so they can be used inline.

With can be called anywhere in the chain to add or clear contexts.

import utils  # contains `log(...)`

value = DotChain(data | iterable).With(utils).method().log().Result()

value = DotChain(data | iterable).With({'utils': utils}).method().utils.log().Result()

value = DotChain(data | iterable).With(self).method().utils.log().Result()

Call inline functions

value = DotChain(data | iterable).method().Call(lambda item: item.property).Result()

Examples

from dotchain import DotChain
import log_utils

# Chaining
order = DotChain(user).get_order('123').cancel().Result()

# Chaining with Piping
email_result = DotChain(user).get_order('123').cancel().Pipe.send_email().Result()

# With lookup contexts
order = DotChain(user).With(log_utils).get_order('123').cancel().Pipe.log_cancel().Result()

order = DotChain(user).With({'log_it': lambda order: log_utils.log_cancel(order)}).Pipe.log_it().Result()

# Inline callables
order = DotChain(user).get_order('123').cancel().Pipe.Call(lambda order: log_utils.log_cancel(order)).Result()

See Tests for more examples and usage.

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

dotchain-0.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

dotchain-0.0.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file dotchain-0.0.1.tar.gz.

File metadata

  • Download URL: dotchain-0.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for dotchain-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1300d893588c3291d0d7661c2b7c4038892a3246608515332de15018904e9e8f
MD5 44a390ce1bd8072ddfbcc89bc5f6ec02
BLAKE2b-256 9a1ca293ca6c3f7cb6650b1838c923c71d52d5d123db30b7019e56d2bc295886

See more details on using hashes here.

File details

Details for the file dotchain-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dotchain-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for dotchain-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c390b1a25285359f119ec3bd6678608d3b4b0f6535f7f4d2faac60fb5a05cd4f
MD5 f626d8ca346dbe51c21e3977a5167023
BLAKE2b-256 392ea8202a908ac724ce2535f11c9722fe0fa020d99fcc5e0569a18e25f28177

See more details on using hashes here.

Supported by

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