{"id":5462,"library":"routes","title":"Routes","description":"Routes is a Python library that re-implements the Rails routing system, enabling developers to map URLs to application actions and generate URLs. It focuses on creating clean, concise, and RESTful URLs with features like named routes, conditional matching, and sub-domain support. The library is currently in maintenance mode, meaning active development is limited, but bug fixes via pull requests are still accepted. The latest stable version is 2.5.1.","status":"active","version":"2.5.1","language":"en","source_language":"en","source_url":"https://github.com/bbangert/routes","tags":["web","routing","url-dispatch","wsgi"],"install":[{"cmd":"pip install routes","lang":"bash","label":"Latest stable version"}],"dependencies":[],"imports":[{"note":"The primary class for defining and managing routes.","symbol":"Mapper","correct":"from routes import Mapper"},{"note":"Provides WSGI middleware for integration.","symbol":"middleware","correct":"from routes import middleware"}],"quickstart":{"code":"from routes import Mapper\n\n# Setup a mapper\nmap = Mapper()\n\n# Connect routes\nmap.connect(None, '/error/{action}/{id}', controller='error')\nmap.connect('home', '/', controller='main', action='index')\n\n# Match a URL\nresult = map.match('/error/myapp/4')\nprint(f\"Match result for '/error/myapp/4': {result}\")\n\nresult_home = map.match('/')\nprint(f\"Match result for '/': {result_home}\")\n\n# Generate a URL\nurl = map.generate(controller='main', action='index')\nprint(f\"Generated URL for main index: {url}\")\n\nerror_url = map.generate(controller='error', action='display', id=123)\nprint(f\"Generated URL for error: {error_url}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize a `Mapper`, connect routes using placeholders and default values, and then match incoming URLs to retrieve controller/action parameters or generate URLs from parameters."},"warnings":[{"fix":"Be aware of the library's maintenance status. For new projects requiring active development or extensive new features in routing, evaluate more actively maintained alternatives. Continue to use `routes` if its current feature set meets your needs and you are comfortable with community-driven bug fixes.","message":"Routes is in maintenance mode. While bug reports are accepted and pull requests with tests will be applied, active feature development is unlikely. Consider this when planning long-term projects or expecting new features.","severity":"deprecated","affected_versions":"2.5.1 and newer"},{"fix":"Ensure your project uses Python 3.5 or newer when using `routes` version 2.5.0 or later. For older Python versions, you would need to pin an older `routes` release, though this is not recommended due to lack of support.","message":"Versions prior to 2.5.0 had specific Python version requirements. Support for Python 2.6, 3.3, and 3.4 was removed in 2.5.0.","severity":"breaking","affected_versions":"< 2.5.0"},{"fix":"Upgrade to `routes` 2.1 or higher to benefit from fixes related to URL generation and caching. If stuck on an older version, thoroughly test URL generation scenarios, especially those involving `SCRIPT_NAME` or custom host/protocol parameters.","message":"Older versions (prior to 2.1) had issues with URL generation and caching, particularly when `SCRIPT_NAME` was involved or with specific parameter passing (e.g., 'host', 'protocol', 'anchor').","severity":"gotcha","affected_versions":"< 2.1"},{"fix":"If migrating from versions prior to 1.9, be aware that named route generation will be more rigid by default. If flexible generation is needed, explicitly set `hardcode_names=False` when initializing the `Mapper`.","message":"In version 1.9, the `Mapper` object's `hardcode_names` argument defaulted to `True`. This means routes generated by name must strictly adhere to the URL pattern.","severity":"breaking","affected_versions":"1.9 - 2.x"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}