{"id":6853,"library":"repath","title":"repath","description":"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.","status":"maintenance","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/synacor/python-repath","tags":["path","regex","expressjs","routing","url","web"],"install":[{"cmd":"pip install repath","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"repath","correct":"import repath"}],"quickstart":{"code":"import repath\n\n# Define an ExpressJS-style path pattern\npath_pattern = \"/user/:id/posts/:post_id\"\n\n# Generate a regular expression and a list of keys (parameters)\nregexp, keys = repath.repath(path_pattern)\n\nprint(f\"Generated Regex: {regexp.pattern}\")\n# Example output: ^\\/user\\/(?:([^\\/]+?))\\/posts\\/(?:([^\\/]+?))\\/?$\n\n# Match a URL against the generated regex\nurl_to_match = \"/user/123/posts/456\"\nmatch = regexp.match(url_to_match)\n\nif match:\n    print(f\"Matched groups: {match.groups()}\")\n    # Example output: ('123', '456')\n    print(f\"Matched parameters: {match.groupdict()}\")\n    # Example output: {'id': '123', 'post_id': '456'}\nelse:\n    print(\"URL did not match the pattern.\")\n\n# You can also compile tokens to generate paths (reverse operation)\ntokens = repath.repath_tokens(\"/files/:name(\\\\d+)\") # Path with a regex constraint\ncompiler = repath.tokens_to_function(tokens)\n\nprint(f\"Compiled path: {compiler({'name': '789'})}\")\n# Example output: /files/789\n# Note: This will raise ValueError if constraints are not met.\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=0.9.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the library's behavior carefully in a Python 3 environment, especially regarding string handling and byte compatibility, if unexpected issues arise.","message":"The 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.","severity":"gotcha","affected_versions":"<=0.9.0"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}