Skip to main content

OnAny… thing happening

Build Maintainability Test Coverage

OnAny is a simple yet powerful event manager library, where you can declare listeners and dispatch as much events as needed to them.

How To

To listen and dispatch events is very simple:

from onany import dispatch, listener

@listener("event.name")
def on_event_name(*args, **kwargs):
    print("I've been called with {} and {}".format(
        args,
        kwargs
    ))

>>> dispatch(
    "event.name",
    "first_param",
    "second_param",
    "third_param",
    first="param",
    second="param",
    third="param")

Should I wait all callbacks to end ?

Nope. You can “threadily” dispatch your events so they don’t need to be waited for the main process.

from onany import disthread, listener

@listener("event.name")
def on_event_name():
    print("I'm gonna be executed on another thread")

>>> disthread("event.name")

Webhook listener

It’s possible declare webhook rules to be dispatched as an inside event. This webhook events can be a powerful tool for communicating to third-party clients that an event is ended.

Listener rules:

  • route
    • type: str

    • description: API route

    • required

  • callback
    • type: callable/function

    • description: Receives request response object if needed

When dispatch or disthread is called is possible define some attributes to be sent in the external API call.

Attributes:

  • data
    • type: dict

    • description: JSON body

  • headers
    • type: dict

    • description: Dictionary declaring headers to be sent

Example:

from onany import dispatch, listener

def event_name_webhook_response(response):
    if response.status_code == 200:
        print("My hook listener worked")

listener("event.name", {
    "route": "https://my.api/hooks",
    "callback": event_name_webhook_response
})

>>> dispatch("event.name", data={
    "some": "payload",
    "I": "wanna",
    "send": "to",
    "hooked": "api"
})

Release files for onany 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onany 0.2.0
File Size Uploaded
onany-0.2.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for onany 0.2.0
File Interpreter ABI Platform
onany-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / onany-0.2.0.tar.gz

Download URL onany-0.2.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
448bb4fd940cf85226332f6734501db7f02987fb5ff619cfba3cb078e1bd1680
BLAKE2b-256 checksum
How to use checksums
5ca118c20c2e857865a782f7d372e5f24e9016f0e6dc5b1b76727e92d849bb81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Release files / onany-0.2.0-py3-none-any.whl

Download URL onany-0.2.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c36b65c30ffba3c0e27fd0aa25cb98bf05b9ad15c1098b95f352764acd447f99
BLAKE2b-256 checksum
How to use checksums
8af3a088a5a09e15b54a31a5524d39f56fe7ce0073bccc8da87646392dad0c27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page