URLTree URL Router
This package provides a tree-oriented URL router. Most URL routers operate by matching a URL against a list of regular expressions until they find one that matches, but this has obvious performance penalties if there are many routes. URLTree is different; routes are stored as a tree, and matching a URL against the set of routes is equivalent to traversing the tree.
The URLTree router supports parameters, and even allows parameter values to be matched against regular expressions or converted by functions. Moreover, as long as these “restrictions” and the variable names are different, several of these parameters can be declared at the same level of a URL tree; this allows a URL with, say, an integer in one location to be mapped to one destination, while a second URL with non-integer values in that same location may be mapped to another destination.
To use URLTree, allocate a URLTree object and use the URLTree.route() method to map a URL pattern to a destination, like so:
mapper = URLTree()
mapper.route("/article", list_articles, "get")
mapper.route("/article", create_article, "post")
mapper.route("/article/{id}", get_article, "get", id=int)
mapper.route("/article/{id}", update_article, "put", id=int)
mapper.route("/article/{id}", delete_article, "delete", id=int)
Upon receiving a request, the destination and the parameters can be retrieved using the URLTree.resolve() method, like so:
# "req.method" is the HTTP method, and "req.url" is the requested # URL dest, params = mapper.resolve(req.method, req.url)
Note that URLTree does not interpret the destination; the examples above use callables, but anything can be used here.
Metadata
Release files for urltree 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| urltree-0.1.0.tar.gz | 13.3 kB | Without provenance | Details for urltree-0.1.0.tar.gz |
Release files / urltree-0.1.0.tar.gz
| Download URL | urltree-0.1.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f04873334e17c5a285d3f41c6add977edc76d38993606f8a398a57617371354
|
|
BLAKE2b-256 checksum How to use checksums |
43094c0f4e55adf54b7dbaab47a7a8e8972566dcc8659f75c5ac90205b2055f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for urltree 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.