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, IMyrrhExt, uri_rd
from myrrh.exts.protocol import StdExtSession
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(IMyrrhExt):
    fullpath = ''
    
    def open(self, uri: str, *, req: urllib.request.Request | None = None) -> HelloSession:
        path = str(URI(uri).path).removeprefix(self.fullpath)  
        return HelloSession(path)
    
    def basepath(self, path: str):
        self.fullpath = 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.core 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.1.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for myrrh_exts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5dfea8f3301844cb79fb2bb60e00f8eee0bb919ec33f41f47d169d36085bf765
MD5 94005659c5c62fe9123003ce7adec890
BLAKE2b-256 4002fa5d98d8acf57db85186a57bf95510c019e444d874af2fdaa164511c8734

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