Skip to main content

extension manager for the myrrh project

Project description

About the Myrrh extension package.

This package is part of the Myrrh project.

It aims to simplify the management and registration of myrrh extensions by using URI.

Requirement

  • Python: 3.11

Installation

To install myrrh-exts, simply execute:

$ pip install myrrh-exts

Getting Started

Myrrh extension package is based on URI, predefined interfaces, and the standard entry point mechanism.

How to define a myrrh extension?

First define your extension by creating a protocol class, a session class, and an entry point class.

Declare the extension using the project configuration file, with the extension URI scheme being the group name and the extension URI path being the entry point name.

Sample implementation of extension.

myexts/hello.py

from myrrh.exts.interfaces import IExtSession, uri_rd
from myrrh.exts.protocol import StdExtSession, MyrrhExtBase
from myrrh.exts.misc import URI
from myrrh.exts.errors import InvalidPath

class IEchoProtocol(IExtProtocol):

    @uri_rd
    @abc.abstractmethod
    def hello(self): ...

class HelloSession(StdExtSession, IEchoProtocol):

    def __init__(self, path):
        super().__init__(IEchoProtocol)

        self.path = path

    def hello(self, myname):
        return f"Hello {myname} from {self.path}"

class Hello(MyrrhExtBase):
    
    def open(self, uri: str, *, req = None) -> HelloSession:
        path = URI(uri).path.removeprefix(self._path)  
        return HelloSession(path)
        
    def extend(self, path: str, _obj):
        raise InvalidPath(path)

myexts/pyproject.toml

...

[myproject.exts]
/my/ext/path = "myext.hello:Hello"

...

myexts/main.py

from myrrh.exts.registry import Registry

Register().loads("myproject.exts")

with Registry().open("myproject.exts:/my/ext/path?=hello&myname=PyAnjel7") as f:
    open_resp = f.read(1)

c = Registry().client("myproject.exts:/my/ext/path")
with c.open():
    client_resp = c.hello('Pyanjel7')

assert open_resp == client_resp

Command line tool

usage: mexts [-h] {push,get,list} uri

positional arguments: {push,get,list} uri

options: -h, --help show this help message and exit

> mexts get "myrrh.exts:/registry?=loaded"
[['myrrh.exts:/registry']]
> mexts get "myrrh.exts:/registry?=__proto__"
[['findall', 'loaded']]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

myrrh_exts-0.2.1-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file myrrh_exts-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: myrrh_exts-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.6

File hashes

Hashes for myrrh_exts-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9def779174eaf94c87a1a8b5d080f8c591c742191113a04be80eea908cd7e828
MD5 41fef61e4b7b8008ccde19aba7a6bb34
BLAKE2b-256 7669ca18803911ebc40a71a48251649fa448462c4e6fa6308e157ad5723086af

See more details on using hashes here.

Supported by

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