Callback library for sync/async python
Project description
Callbacker
Callbacker is a lightweight and flexible callback library for both synchronous and asynchronous Python programming. It provides a simple yet powerful way to implement event-driven programming patterns in Python.
Features
- Support for both synchronous and asynchronous callbacks
- Decorator-based event registration
- Type-safe event handling
- Easy to integrate with existing codebases
- Minimal dependencies (only requires
frozenlist) - Python 3.11+ support
- Thread-safe event dispatching
Installation
You can install Callbacker using PDM:
pip callbacker
Quick Start
Here's a simple example of how to use Callbacker:
from callbacker.callback import EventWrapper
# Create an event
custom_event = EventWrapper()
# Register a callback using decorator syntax
@custom_event
async def on_event(data):
print(f"Received event with data: {data}")
# Trigger the event asynchronously
await custom_event.aio_send("Hello, World!")
Advanced Usage
Class-based Events
from callbacker.callback import event, contextevent
class MyClass:
@event
async def on_data(self, data):
"""This is a regular event"""
print(f"Received data: {data}")
@contextevent
async def on_update(self, context, data):
"""This event includes the class instance as context"""
print(f"Update from {context} with data: {data}")
Synchronous Callbacks
from callbacker.callback import EventWrapper
event = EventWrapper()
@event
def sync_handler(data):
print(f"Handling {data} synchronously")
# Trigger synchronously
event.send("test data")
Documentation
For more detailed documentation and examples, please visit the documentation page.
Contributing
Contributions are welcome! Please read our Contributing Guidelines for details on how to submit pull requests, report issues, and contribute to the project.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 callbacker-0.1.0.tar.gz.
File metadata
- Download URL: callbacker-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.22.1 CPython/3.13.1 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70e2ec97e53982e82eaa80efcf3c00e5678f820db713db1e786107239867ac34
|
|
| MD5 |
5eb3f7203c256974e52fc60352308f3c
|
|
| BLAKE2b-256 |
d0a56f6bc97a1a05756c9a63697afb2d44a6bd0a656f9892a0dd6d191cbc53a8
|
File details
Details for the file callbacker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: callbacker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.22.1 CPython/3.13.1 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80fd423cf837d4c0a38badafcb023da23c02b5e55070d610e6a85f312b37d0a2
|
|
| MD5 |
3effdf1aafdd0206504e3747f9f7ae75
|
|
| BLAKE2b-256 |
0d6dcbaed153665a0e295e50d9e10c933be15656a03f92884bd2f0bca6804d00
|