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_thenmethod 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
Filteras 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_service_compose-0.0.0.tar.gz.
File metadata
- Download URL: simple_service_compose-0.0.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34973d1ea2bb19718c5d4d870b66956bbf4b6492faab29fa706ab6c76531288a
|
|
| MD5 |
565189e33e6d49283358ba6c9f5ffefe
|
|
| BLAKE2b-256 |
be736a97f3d5772f564ec324b12503ef5dd6d4044bab75c6bdd5be6a62cc6724
|
File details
Details for the file simple_service_compose-0.0.0-py3-none-any.whl.
File metadata
- Download URL: simple_service_compose-0.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff53213eff0e503c947aba7c9d443a5d194b20d048c545547a0bfd5c941bf7bf
|
|
| MD5 |
386b3b8891666d188861c632ed01ab02
|
|
| BLAKE2b-256 |
4c779b5b6bf97e4d0592fbf6476b4a7d22586a28e8284b0c83b26d5f4ef94b88
|