Registry / serialization / repath

repath

JSON →
library0.9.0pypypi✓ verified 87d ago

repath is a Python library that ports the pathToRegexp Node.js module, designed to generate regular expressions from ExpressJS-style path patterns. It enables parsing paths and extracting parameters using Python's named capture groups. The current version is 0.9.0, released in October 2019, and the project appears to be in maintenance mode due to its last update date.

pip install repath
INSTALL
IMPORT
SIG · REPATH
R
repath
serializationpythonv0.9.0
Install
1.6s avg
Import
12ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.012s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

repath
import repath

This quickstart demonstrates how to use `repath` to convert ExpressJS-style path patterns into Python regular expressions, match URLs against these patterns to extract parameters, and generate paths from parameters using the reverse compilation.

import repath # Define an ExpressJS-style path pattern path_pattern = "/user/:id/posts/:post_id" # Generate a regular expression and a list of keys (parameters) regexp, keys = repath.repath(path_pattern) print(f"Generated Regex: {regexp.pattern}") # Example output: ^\/user\/(?:([^\/]+?))\/posts\/(?:([^\/]+?))\/?$ # Match a URL against the generated regex url_to_match = "/user/123/posts/456" match = regexp.match(url_to_match) if match: print(f"Matched groups: {match.groups()}") # Example output: ('123', '456') print(f"Matched parameters: {match.groupdict()}") # Example output: {'id': '123', 'post_id': '456'} else: print("URL did not match the pattern.") # You can also compile tokens to generate paths (reverse operation) tokens = repath.repath_tokens("/files/:name(\\d+)") # Path with a regex constraint compiler = repath.tokens_to_function(tokens) print(f"Compiled path: {compiler({'name': '789'})}") # Example output: /files/789 # Note: This will raise ValueError if constraints are not met.
Debug
Known issues
gotchaThe library has not been updated since October 2019. While it may still function, there's a risk of compatibility issues with newer Python versions (e.g., Python 3.8+) or modern web frameworks. Users should test thoroughly.
fix
Thoroughly test `repath` with your specific Python version and dependencies. Consider alternative, actively maintained libraries for new projects if extensive regex path matching is required.
affects: <=0.9.0
gotchaThe package name `repath` can be easily confused with other Python libraries such as `rpath`, `rpaths`, `multipath`, or Django's `re_path` function, which serve different purposes related to file paths or URL routing with raw regular expressions.
fix
Ensure you are installing and importing `repath` specifically for ExpressJS-style path pattern conversion. Double-check documentation to confirm the correct library for your use case.
affects: All versions
gotchaThe PyPI classifier includes 'Programming Language :: Python :: 2', indicating historical Python 2 compatibility. Although a Python 3 wheel is available, reliance on older design patterns might exist, potentially causing subtle issues in Python 3-only environments.
fix
Review the library's behavior carefully in a Python 3 environment, especially regarding string handling and byte compatibility, if unexpected issues arise.
affects: <=0.9.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'repath'
The 'repath' library has not been installed in the current Python environment.
fix
pip install repath
TypeError: path pattern must be a string
The `parse` or `compile` function was called with a `pattern` argument that is not a string (e.g., an integer or None).
fix
Ensure the `pattern` argument passed to `repath.parse` or `repath.compile` is always a string, for example: `repath.parse('/users/<id>')`.
repath.tokenizer.LexerError: Unexpected character '<' at position X.
The path pattern provided to `repath.parse` or `repath.compile` is malformed and does not conform to ExpressJS-style path syntax.
fix
Correct the path pattern to follow valid ExpressJS-style syntax, such as `/users/<id>` or `/items/:slug`, ensuring proper parameter delimiters and structure.
KeyError: 'name'
Attempting to access the 'name' key on a token dictionary returned by `repath.parse` that represents a static path segment, not a parameter.
fix
Before accessing `token['name']`, check if the 'name' key exists in the token dictionary, for example: `if 'name' in token: print(token['name'])`.
Upgrade
Version history
0.9.0latest on PyPI · released Oct 8, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources