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.0.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.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for simple_service_compose-0.0.0.tar.gz
Algorithm Hash digest
SHA256 34973d1ea2bb19718c5d4d870b66956bbf4b6492faab29fa706ab6c76531288a
MD5 565189e33e6d49283358ba6c9f5ffefe
BLAKE2b-256 be736a97f3d5772f564ec324b12503ef5dd6d4044bab75c6bdd5be6a62cc6724

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_service_compose-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff53213eff0e503c947aba7c9d443a5d194b20d048c545547a0bfd5c941bf7bf
MD5 386b3b8891666d188861c632ed01ab02
BLAKE2b-256 4c779b5b6bf97e4d0592fbf6476b4a7d22586a28e8284b0c83b26d5f4ef94b88

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