Skip to main content

A simple Python packaging for managing event-like actions and validating handlers argument types.

Project description

Actions-python

Overview

Actions-python is a Python package designed to manage actions with event-driven behavior. It provides a flexible way to connect handlers (callbacks) to actions, ensuring that handler argument types are validated before invocation. This helps maintain strict type consistency while enabling dynamic behavior in event-driven systems.

Features

  • Event-driven architecture: Connect handlers to actions and invoke them when the action is triggered.
  • Type validation: Ensures that handler argument types match the expected types defined when the action is initialized.
  • Dynamic handling: Allows flexible addition of handlers at runtime, each with its own argument type validation.
  • Supports multiple argument types: Can handle multiple types of arguments for a single action.

Installation

To install the project you can use pip:

pip install https://github.com/Allorak/actions-python

Or install from PyPI index:

pip install actions_python

Core ideas

  • Actions: An action is an event that can have one or more handlers (callbacks) connected to it. When the action is triggered, all handlers are invoked with the specified arguments.
  • Handlers: Callbacks that are connected to actions. Each handler should expect arguments of a specific type, which are validated at both the connection stage and the invocation stage.
  • Type validation: When a handler is connected, the types of its arguments are validated to ensure they match the expected types. Similarly, when invoking the action, arguments are validated against the expected types.

Usage

For creating an action initialize a variable of Action type and specify types of action's params

from actions import Action

class Test:
    def __init__(self):
        self.example_action = Action(int, str)

    def fire(self):
        self.example_action.invoke(0, "test")

def print_callback(number: int, text: str):
    print(f"Number: {number} | Text: {text}")

test = Test()
test.example_action.connect(print_callback)
test.fire()

Example

Usage examples can be found in examples/ folder

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

actions_python-0.7.5.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

actions_python-0.7.5-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file actions_python-0.7.5.tar.gz.

File metadata

  • Download URL: actions_python-0.7.5.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for actions_python-0.7.5.tar.gz
Algorithm Hash digest
SHA256 a1b88f86ae93c5690dd5cefe5557224747ca33643e36d56494ae9f458363797b
MD5 55f656eea4944329ee9716019fb461c5
BLAKE2b-256 c8e45b4c69ff0b7519be60c81ecd9ac54e10e80219fdee79654fa253e392966a

See more details on using hashes here.

File details

Details for the file actions_python-0.7.5-py3-none-any.whl.

File metadata

  • Download URL: actions_python-0.7.5-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for actions_python-0.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 731e26336575dae022cb781cb4a28b232e6f33a4ebf61e4d170ab6a4822147a2
MD5 9717c29007bc4f4977a60f9d62763f9e
BLAKE2b-256 fb8989e6c8b509810e7af8f295c3084704d0aa4c490ebb2216fbaf792edacfc1

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