An arcane-powered python hooking library for sane humans
Project description
Arcane Hooker
I'm a hooker from Silvermoon City. Let me show you the Arcane way to Python
Hooker is a hooking library that tries to simplify event firing and catching. It gives the ability to plugin creators to create plugins for many different parts, without having to break the logic in separate destinations, if it's not needed. The main features include:
- Event declaration with help message support
Waterfallevents that pass their output as arguments to next hook- Simple CLI tool to view all defined events of a project and its help messages
- Functions decorators to hook on events
- Dependency requirement for hooks (
ahook has to be run beforeb) HOOKER_SCRIPTSenvironmental variable allows to load additional scripts (aka plugins)- Wildcard hooks that are fired on all events
- When a hook accepts the
__retvals__argument, the returned values of the previous hooks (and the whole hook functions) will be passed into it as an OrderedDict - Python 2 compatibility - I'll try to keep that for as long as I can
Terminology:
Project: A project that uses HookerPlugin: A piece of code that adds functionality to aProjectusinghooksEvent: A name for something thatPluginscan hook on. It is called on specific times (that theProjectauthor has programmed) so thatPluginscan add functionalityHook: A function that thePlugincreator wrote and is declared as hook using the@hooker.hookdecorator. Contains at least oneEventname (or none if its a wildcard hook) and optionallyDependenciesDependency: AHookcan declare to be called after a plugin has run.Dependencycan include the name(s) of the python module(s) (NOT the function name) that include hooks that need to be run before theHook
For documentation check the wiki
Installation
pip install -U hooker
Usage
To find defined hooks in a project use python -m hooker <python file/module directory>
Example:
$ py -m hooker example/crypter/crypter.py
pre_open_in: Input file will open. Arguments: path<str>. Return: path<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:6
pre_open_out: Output file will open. Arguments: path<str>. Return: path<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:7
encrypt: Encrypt data. Arguments: data<bytearray>. Return: data<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:8
decrypt: Decrypt data. Arguments: data<bytearray>. Return: data<str> - /home/dzervas/Lab/satori/hooker/example/crypter/crypter.py:9
As a Project Author to use hooker you have to declare an event and then fire it
Example:
# project.py
import hooker
hooker.EVENTS.append("test", "Fired after Hello World is printed")
print("Hello World")
hooker.EVENTS["test"]()
As a Plugin Creator to extend a project using hooker, you have to create a function
using the @hooker.hook decorator and define the event you want to hook on:
Example:
# my_plugin.py
import hooker
@hooker.hook("test")
def hello():
print("Goodbye World")
Now to use the plugin, you either have to import it in the project, or execute the
project using the environment variable HOOKER_SCRIPTS as follows:
$ HOOKER_SCRIPTS=my_plugin python project.py
Hello World
Goodbye World
Used in
While the code is not a mess, I'm using a fair bit of python magic. The target is to provide the simplest and most convenient API for both project and plugin authors.
If you have a better way to do something, at least open an issue to discuss it, I'm very interested!
Happy Hacking! :)
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 hooker-1.0.2.tar.gz.
File metadata
- Download URL: hooker-1.0.2.tar.gz
- Upload date:
- Size: 27.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcc72c8045ac3449e1661d70514219e96193182316d42cd9738118be3880010b
|
|
| MD5 |
5ee6abb5c7a3b84e76eff36df7fad200
|
|
| BLAKE2b-256 |
88084f230331da52f7c1c06778fadaa1be33ac224ef669163f77ff7700ba3377
|
File details
Details for the file hooker-1.0.2-py3-none-any.whl.
File metadata
- Download URL: hooker-1.0.2-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19f9ca06f2e1bddb6a0c475d6f4bd5f1f9d66eca68bf1c53a8cf0a3793c5521e
|
|
| MD5 |
48c58cd460587e07ff0edbca759d984e
|
|
| BLAKE2b-256 |
151d12d351e52ac8b896338ca79d69153e38b90813faeadca37038b4a818af7f
|