Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

An Attribute Router/Chainer For Any Class

Project description

Attribute Router

Travis (.org) PyPI - Downloads PyPI - Python Version GitHub release GitHub

Attribute Router is a library that chains calls of attributes of class and if regex matches it returns method.

Quick Start

import re

from attribute_router import Router


class Printer(Router):
    def __init__(self):
        super().__init__(
            routes={
                re.compile(" (.*) PRINT"): self.print_match
            },
            join_char=" "
        )

    def print_match(self, prefix, _match):
        print(prefix, _match.group(1))

Printer().hello.world('!').again.PRINT("Hello and")

So to define routes we use compiled regex and the method itself also don't forget to inherit from attribute_router.Router


Installation

Library is on PyPi so just run

pip install AttributeRouter

Project details


Release history Release notifications

This version

1.0.0

Download files

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

Files for AttributeRouter, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size AttributeRouter-1.0.0-py3-none-any.whl (3.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size AttributeRouter-1.0.0.tar.gz (2.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page