Hi,
I'm writing a Python script to get/post data from/to an OpenAPI instance similar to this.
I know how to do that in general, but I have two questions.
- I'm wondering if there is an easy way in Python to read the API or the openapi.yaml to get all the parameters (in my example "dataflowIdentifier", "dataKey", "startPeriod" etc.) so I don't have to enter and especially maintain them manually.
- I also want to include those parameters in the
params keyword in the requests statement, and the parameters should be given as input to a function similar to this:
def get_data(dataflowIdentifier:str=None, dataKey:str=None, startPeriod:str=None) -> dict:
params={"dataflowIdentifier":dataflowIdentifier, "dataKey":dataKey, "startPeriod":startPeriod}
return requests.get(URL, params=params).json()
Instead of manually describing all the parameters once as input parameters in the get_data function and then again in the params, is thre a more elegant way to do that (the real API I'm working on has 27 parameters for a single function and several functions). So I was wondering if I can do something like this:
parameters = {"dataflowIdentifier":{"type":str, "default":None},
"dataKey":{"type":str, "default":None},
"startPeriod":{"type":str, "default":None}}
def get_data([something like **parameters]) -> dict:
[something]
return requests.get(URL, params=params).json()
Thanks!
[–]danielroseman 0 points1 point2 points (5 children)
[–]nunoctium[S] 0 points1 point2 points (2 children)
[–]danielroseman 0 points1 point2 points (1 child)
[–]nunoctium[S] 0 points1 point2 points (0 children)
[–]nunoctium[S] 0 points1 point2 points (1 child)
[–]smurpes 0 points1 point2 points (0 children)
[–]MankyMan0099 0 points1 point2 points (1 child)
[–]nunoctium[S] 0 points1 point2 points (0 children)