Skip to main content

Framework for multi-client Pyrogram programs with flexible plugin support.

Project description

PyMultigram

The idea behind this library is to create tooling which allows multiple Pyrogram clients to run in a single application sharing the same handlers. Ultimately it should be possible to create both handlers and clients from a configuration file which allows to mix and match handlers.

Why?

There are several use cases where this would be useful. Firstly, with even a single client it could provide a way to create an application which can easily be configured to enable or disable certain features. Secondly, it would allow the creation of multiple bots which (partly) share the same functionality. Multi-Tenancy for bots basically. As an added benefit generic handler could be build (and packaged) to be shared between applications.

But most importantly, it seemed like a fun thing to try ;-)

Usage

To be able to store state for multiple clients and allow for reuse handler methods should be inside a class which inherits from multigram.MultiHandler. This also means multiple instances of the same handler (with perhaps a different configuration) can exist within the same application.

The basic flow is to create instances of handler classes and Pyrogram clients. Then on each of the handler classes call set_clients() to assign (a selection of) the clients to that handler.

Once the clients are started messages should start to flow into the methods decorated with @multigram.on_message(). This decorator is a drop in replacement for the on_message() in pyrogram. It adds one named parameter scope which may contain a callable to filter clients. You can use the presets multigram.ALL, multigram.BOTS or multigram.USERS (with ALL being the default value), or pass your own client filtering method.

TODO

  • Build a pip package and publish to PyPi
  • The usual, samples, unit tests, documentation...
  • A way to store metadata with clients and use that as a filter or within the handler.
  • A way to assign handlers to clients instead of the reverse.
  • A way to configure it all without code, config in something like json or yaml.
  • A way change add/remove clients or handlers at runtime.
  • A way to reload a file based config at runtime.
  • Maybe a minimal rest API to make runtime config changes.
  • Add a kitchen sink.

Development

Contributions are welcome. I'm following git-flow, so please make pull-requests againts the develop branch.

I'm using Eclipse with Pydev, project files are included. But it's plain Python so you should be able to use your favorite IDE.

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

PyMultigram-0.0.4.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

PyMultigram-0.0.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file PyMultigram-0.0.4.tar.gz.

File metadata

  • Download URL: PyMultigram-0.0.4.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for PyMultigram-0.0.4.tar.gz
Algorithm Hash digest
SHA256 dbadfc68388de9d77c57d2296a33fa81129ca360902d574d3f8fd7524cc21fd6
MD5 831e522e70a756aee14a51f706a85308
BLAKE2b-256 d22237f88bd7271b4be91290dff2ce7b0f35e05f15a23bbefdbfb7217be7c000

See more details on using hashes here.

File details

Details for the file PyMultigram-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: PyMultigram-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for PyMultigram-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 db25465d494854192c550ff12ca674d185074ad16812d40b59f63a0e69800aab
MD5 f15ce1e131c83377656747e5333b22e4
BLAKE2b-256 bc35a861a714160c1e5006e11e7d2dffe768fb2ac9e66907d9bccfd833140c98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page