Skip to main content

Lightweight implementation of Finagle's Service and composable Filter types.

Project description

Introduction

This library is a Python implementation of Finagle's Service and Filter abstractions.

Purpose

The ability to compose methods is generically useful, and it's nice to have a common dependency that creates this abstraction.

Usage

Create a Service

A Service[A, B] is a Callabe[[A], Awaitable[B]], generally implemented like:

async def my_function(inp: A) -> B:
    # Do some awaitable work
    result = await ...
    return result

A Filter[A, B, C, D] composes logic with a service. A Filter is a decorator/transformer on a service. Composing a Filter[A, B, C, D] with a Service[C, D] returns a new Service[A, B].

A SimpleFilter[A, B] is represents the common case of a decorator that does not transform the input or output in anyway. A SimpleFilter[A, B] is a Filter[A, B, A, B].

A Filter might implement timeout logic on a service, add observability to it, map between domain types, etc.

A Filter is additionally composable with another Filter. Composing a Filter[A, B, C, D] with a Filter[C, D, E, F] returns a new Filter[A, B, E, F]. That Filter[A, B, E, F] could then be composed with another with a Service[E, F] to produce a new Service[A, B]. (Of course, the Filter[A, B, E, F] could also be composed with another Filter[E, F, _, _].)

A Filter gets composed with another Filter using the .and_then method. A Filter gets composed with a Service with the .and_then_service method.

For concrete examples of:

  • building services,
  • building filters,
  • composing filters with services, and
  • composing filters with other filters

see: tests/simple_service_compose/test_service.py.

Known Limitations

  • In an idealized version (and in the Finagle implementation), filters would compose with servcie using the same .and_then method name that is used to compose with other filters. Pull requests and issues are welcome.
  • The original Finagle implementaion is careful to declare the generic types on Filter as contravariant or covariant, as applicable. We haven't found this to be necessary for our use cases yet. Pull requests and issues are welcome.

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

simple_service_compose-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

simple_service_compose-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file simple_service_compose-0.1.0.tar.gz.

File metadata

File hashes

Hashes for simple_service_compose-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5c77cca22232ed6b459c4dfca9160672a1ad76b5813a3bcc8977862a37a1992d
MD5 ecc520346913bf104ab058453d002d2e
BLAKE2b-256 e616f4a54215d4f35f96086c7fae6013be16ed604186f8dc529605958f808012

See more details on using hashes here.

File details

Details for the file simple_service_compose-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_service_compose-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8e362acd3d6ffe383b1a63bf245c08873ca7f19cdfacf99222387481a79b36
MD5 7685dc09d342fa1a7d05dddf3d2b288a
BLAKE2b-256 af37049a8bd70a55af39570d9afe65425ec3e48f1b65c71bddd6f34c9069a113

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