Search code examples
python-3.xcherrypy

How to add versioning to APIs in cherryPy


I want to version my APIs (written in python: using cherrypy- version 13.1.0), but simply giving the alias as /v1/apiName throws a "path not found" error. Is there any way to do this using cherryPy. (I did consider using FastAPI for this, but for my particular usecase, cherryPy outperformed FastAPI in load tests). Example of my API:

Class APIClass:

   @cherrypy.expose(alias="v1/apiName")
   @cherrypy.tools.json_in()
   @cherrypy.tools.json_out()
   def does_stuff():
      **do stuff**

Solution

  • The best solution for me in this scenario is using cherrypy.popargs. Leaving Sylvian Hellegourach's answer here: Friendly URL for a REST WebService with CherryPy