Skip to main content

Library used for chaining together synchronous and asynchronous functions for data transformation

Project description

aChain

Library used for chaining together synchronous and asynchronous functions for data transformation

What does this do?

The achain.Chain class allows for the construction of chained synchronous and asynchronous functions

Example:

import typing
import json
from datetime import datetime, timedelta

from achain import Chain

SERVICE_URL = "https://www.service.com/api"
"""The address of some service containing data of interest"""

async def get_data(url, **kwargs) -> str:
    """
    Gets raw text from the given URL with the given query parameters
    """
    ...

def normalize_data(
    data: typing.Dict[str, typing.Any]
) -> typing.Dict[str, typing.Dict[str, typing.Any]]:
    """
    Transforms the passed data into one that is easier to deserialize
    """
    ...

class ExampleClass:
    """
    An example of a class that may be constructed from the generated data
    """
    def __init__(self, **kwargs):
        """Constructor"""
        ...

async def main():
    """
    Create lists of remote data
    """
    # Declare your chain
    chain: Chain[typing.List[ExampleClass]] = Chain(
        get_data,
        url=SERVICE_URL
    ).then(
        json.loads
    ).then(
        normalize_data
    ).then(
        lambda data: [ExampleClass(**values) for values in data.values()]
    )
    
    # Call Asynchronously
    yesterdays_data: typing.List[ExampleClass] = await chain(
        start=datetime.now() - timedelta(hours=48),
        end=datetime.now() - timedelta(hours=24)
    )

    # Call Synchronously
    todays_data: typing.List[ExampleClass] = chain.execute_synchronously(
        start=datetime.now() - timedelta(hours=24),
        end=datetime.now
    )

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

achain-0.1.1.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

achain-0.1.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file achain-0.1.1.tar.gz.

File metadata

  • Download URL: achain-0.1.1.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for achain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f545d3f50c8326e6f4a2b4c855cd0718971afe0afc0a537e0b13af0994d50a4
MD5 04a07d33e807131608423f617f6d856e
BLAKE2b-256 841684d67411f2f514d3ae45233e444d272ff8edc0be9ff561a2040b8f141ecf

See more details on using hashes here.

File details

Details for the file achain-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: achain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for achain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 982138a512cc1fd02f665c719e629da3c2f19019a385eb6da6e876b79482630e
MD5 c5390c0c728e397fd0f6ca056d5e444e
BLAKE2b-256 fad151e772fc81043aea94070a639ff6a401cd86c1fa90b05f61985eaae8e2bc

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