Skip to main content

A small Python module to provide convenient mapping between Python functions and text input

Project description

Latest PyPI version Latest Travis CI build status

A small Python module to provide convenient mapping between Python functions and text input.


You know Flask, right? You love the decorator-routing they use, right? - This is exactly the same, but for any text and not URLs and with REGEX!

Here is how you use it:

First you need to create an instance of the FuncMapper:

from funcmap import FuncMapper

mapper = FuncMapper()

And now you map, map, map:'call my_func')
def my_func():
    """We can map simple functions.

    Just pass a phrase to the map decorator.
    return 'I, my_func, have been called''(?P<first>\d+)\+(?P<second>\d+)')
def adder(first, second):
    """We can map functions with arguments.

    All named capture groups (this is a capture group named first: (?P<first>\d+)) are passed as keyword-arguments to
    function. So make sure the names of your capture groups fit the names of your function arguments.
    Unnamed capture groups as positional arguments are NOT supported to avoid some edge-cases!
    return '{} + {} = {}'.format(first, second, int(first) + int(second))

Not enough mapping? - Than map some more! Double-Map-Time!'I am Fred')'No, I am Joe')
def multi_name():
    """We can map multiple Regex-expressions to the same function."""
    return 'I have multiple names!'

And no we have a function with some self esteem:

>>> print(mapper('call my_func'))
'I, my_func, have been called'

A silly calculator:

>>> print(mapper('3+5'))
'3 + 5 = 8'
>>> print(mapper('10+2'))
'10 + 2 = 12'

And this schizophrenic guy:

>>> print('I am Fred')
'I have multiple names!'
>>> print('No, I am Joe')
'I have multiple names!'

For more guidance check the examples folder and the method docstrings.

Why the heck do I need that?

Because it uses some awesome Python stuff, of course! - But seriously, the idea is to use it as tiny helper-framework when some simple language logic is needed. A prime example would be something like a chatbot or some kind of AI-Assistant.

I developed this little thing, because I am planning on building like a very dumb language-shortcut engine to make some simple tasks voice or SMS/Message controllable. I currently don’t have time for that, but I wanted to start somewhere. If you have the time, STEAL MY IDEA, MAKE IT, SHARE IT, AND BE AWESOME!

Can it do …?

Probably not… yet! Currently I only implemented the bare minimum I needed. If I will do more work with this library I will very likely find more stuff I need. Till then, it is your turn! If you are missing a feature let me know! I will try my best to make it work for you!

What is this RegEx you are talking about?

Regular Expressions (RegEx) are super cool language-processing-magic, if one understands them. I do… sometimes. If you want to
master the RegEx learn here and test your skills here.


pip install funcmap

or if you want to develop an awesome new feature (yes, I know you want to!):

git clone
cd funcmap
pip install -e .

What do I need?! (Requirements)

Na Na Na Nothing

But, does it work?! (Tests)

YES! I hope. If in doubt, run

python test


The module is compatible with Python 3 only. It uses re.fullmatch, which is not backwards compatible. If you really need a version that is compatible with Python 2.7, let me know. I guess it should be possible to fix that.


This package is licenced under a MIT licence (Copyright (c) 2017 Arne Küderle)


funcmap was written by Arne Küderle.

Project details

Download files

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

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

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page