A simple, class based dispatcher
Project description
Callouts
A minimalist dispatch system for python module lose coupling.
Imagine we had an application that checks weather for one place, but using multiple service. The functionality to get weather for a specific service could be implemented in individual modules.
To implement this with callouts, we first need to implement the extensibility base by creating a class with the @callouts.base decorator.
@callouts.base
class Weather:
def get_for(location: str) -> str:
pass
Now, individual implementations can be added
simply by extending the class and implementing the get_for method.
class FirstWeatherService(Weather):
def get_for(location: str) -> str:
return 'sunny'
class SecondWeatherService(Weather):
def get_for(location: str) -> str:
return 'cloudy'
with those definition in place, as soon as the modes are loaded it is possible to get both weathers by calling the get_for method on the Weather class:
print(Weather.get_for('place'))
will print out
['sunny', 'cloudy']
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 callouts-0.2.0-py3.10.egg.
File metadata
- Download URL: callouts-0.2.0-py3.10.egg
- Upload date:
- Size: 4.4 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
330176470e6cf58f90a9320815903af55b1a9115d5dfcf9d48fcd1b01dac1e1d
|
|
| MD5 |
945d01e71b47dfb2de4be163fb81d015
|
|
| BLAKE2b-256 |
4bb26c3eb7baa6ec7f0ac187ed1bf621e5ee6f4f2efa06e0ffc6030ea0b90285
|