我有一个生成字典模板的函数。这个函数由几个生成器组成,需要一个参数(即carrier
),并且有很多可选参数(关键字参数-**kwargs
)。
def main_builder(carrier, **params):
output = SamplerBuilder(DEFAULT_JSON)
output.generate_flight(carrier)
output.generate_airline_info(carrier)
output.generate_locations()
output.generate_passengers()
output.generate_contact_info()
output.generate_payment_card_info()
output.configs(**params)
result = output.input_json
return result
# example of function call
examplex = main_builder("3M", proxy="5.39.69.171:8888", card=Visa, passengers={"ADT":2, "CHD":1}, bags=2)
我希望将这个函数部署到FastAPI端点。我已经成功地将其应用于carrier
,但是如何将**kwargs
设置为该函数的参数?
@app.get("/carrier/{carrier_code}", response_class=PrettyJSONResponse) # params/kwargs??
async def get_carrier(carrier_code):
output_json = main_builder(carrier_code)
return airline_input_json
json
负载,但我想看到两种解决方案。 - PetrSevcik