Skip to main content

Routes for speed

Project description

Autoroutes

Routes for speed.

Install

pip install autoroutes

API

# Create a Routes instance
from autoroutes import Routes
routes = Routes()

# Register a new route
routes.add('path/to/resource/{id}', something='value', anything='else')

# Try to match a route
routes.match('path/to/resource/1234')
> ({'something': 'value', 'anything': 'else'}, {'id': '1234'})

Placeholders

Placeholders are defined by a curly brace pair: path/{var}. By default, this will match any character but the slash ('/').

It's possible to control the placeholder type, either by:

  • using a named type: alnum, digit, alpha, path (matches everything), string (default):

      path/to/{var:digit}
      path/to/{var:string}  # Same as path/to/{var}
    
  • using a normal regex (slower; also note that regex containing curly braces is not yet supported)

      path/to/{var:\d\d\d}
    

Placeholders can appear anywhere in the path

path/to/file.{ext}
path/to/{name}.{ext}

Building from source

pip install cython
make compile
python setup.py develop

Tests

make test

Benchmark

See Benchmark for more details.

Acknowledgements

This package has been first made as a Cython port of the R3 C router. See also python-r3, which was a first attempt to wrap R3. I was unhappy with the stability, and more curious about Cython, so I tried to make a first POC port, and was happy with it.

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

autoroutes-0.2.3.tar.gz (78.1 kB view details)

Uploaded Source

File details

Details for the file autoroutes-0.2.3.tar.gz.

File metadata

  • Download URL: autoroutes-0.2.3.tar.gz
  • Upload date:
  • Size: 78.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.1

File hashes

Hashes for autoroutes-0.2.3.tar.gz
Algorithm Hash digest
SHA256 2b8af8fe696e6a9dc37a54340e875bfa746a15ccb9851a18244a7d3decb83c70
MD5 fac86d25484bf7509dbfb13b80ff397a
BLAKE2b-256 9a9be0ee14b292008ff068e7297b4f58a4885e0d5de3ec7dd61e42ca023e9c1d

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