It depends on if you are using Functions V1 or Functions V2. Note that neither is currently in General Availability: the Python language in V1 is considered experimental and will likely never go GA. The Python language worker for Functions V2 just went into private preview, and is currently in active development (see here). Overall, I highly recommend using Functions 2.0 for the best python support, and because it supports Python 3, while I believe that Functions V1 only supports Python 2.
With that said, the two versions both use the route
parameter on the HTTP trigger function.json to configure the routes. To actually read the values, the two versions have very different approaches.
V1
You can set the custom route the same way you do for Node and C# in the function.json, by setting the "route" field of your HTTP Trigger binding. The route parameters are available as strings on the environment variables REQ_PARAMS_{route_param_name_as_upper_case}
. So for your example, the route parameter values for name
and id
would be REQ_PARAMS_NAME
and REQ_PARAMS_ID
respectively.
V2
Again, you set the custom route in the function.json file the same way you do in all other languages. The route parameters are attached on the http request object as the property route_params
, with the type of Mapping[str, str]
def main(req):
name = req.route_params.get('name')
return f'Hello, {name}!'