marier-nico / event-processor Goto Github PK
View Code? Open in Web Editor NEWPythonic event-processing library based on decorators
Home Page: https://event-processor.readthedocs.io/
License: MIT License
Pythonic event-processing library based on decorators
Home Page: https://event-processor.readthedocs.io/
License: MIT License
The feature might be used like this :
input = {
"Records": [
{
"Sns": {
"Message": json.dumps({"key": "value"})
}
}
]
}
@event_processor.processor({"Records.0.Sns.Message.key": "value"}, autoparse=True)
def my_processor(_event):
pass
The autoparse
argument could make the processors try to parse string to a dict if there's more to go. For example, there's a key after Message
, but Message
is a string, so we try to json.loads
the value and keep going.
The default should be False.
For JSON parsing, consider using https://pypi.org/project/jsoncomment/ for more flexible parsing (perhaps with a flexible_json
keyword argument in the decorator. Though, this feature should be optional and opt-in (use extras_require
). Thanks to @mobouchardcoveo for this suggestion!
Using this feature might look a little bit like this :
input = {
"Records": [
{
"Sns": {
"Message": "msg"
}
}
]
}
@event_processor.processor({"Records.0.Sns.Message": "msg"})
def my_processor(_event):
pass
If event["Records"]
is indeed an array, but the index is invalid for that array, simply do not call the processor. No error should be raised for a bad index.
If event["Records"]
is a dict that contains the key 0
, then treat the filter as any other filter which does not deal with arrays.
It should be possible to hook into the library to run some code before or after processors. One nice way to do it would be similar to python decorators, by essentially wrapping the processor in a new function.
Sample Usage
def my_hook(processor: Processor):
start = time.time_ns()
processor() # The hook needs to run the processor
end = time.time_ns()
print(f"The processor {processor.name} took {end - start}ns to run")
Use-Cases
Caveats
functools.partial
to make sure the hooks don't need to deal with them?A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.