python - Best practices for passing many optional params to a function that wraps a REST API -


this opinionated suppose curious if there common "best practice" pattern this.

say have api i'm wrapping takes 1 of many (30+) optional parameters pass uri. passing 30 keywords ridiculous, chose following:

from urllib.parse import urlencode  def example(required,**kwargs):     print('wwww.exampleapi.com/limit='+required+'&{}'           .format(urlencode(kwargs)))  example('foobar',a=1,b=2,c=3) >>> wwww.exampleapi.com/limit=foobar&a=1&c=3&b=2 

this allows me flexibility have optional keyword arguments without having specify them individually in parameters list, , don't have use kwargs.get() billion times. downside if want validate arguments passed in valid api parameters, need maintain list or mapping of sort , check **kwargs membership in list since i'm not using kwargs.get (or @ least that's i've thought far). can point api documentation parameters use.

is there glaring problems should aware of using approach?


Comments

Popular posts from this blog

Receive udp packets in android gstreamer -

php - Extract Text from HTTP referer -

matplotlib - PYTHON: Annotate boxes disapear dependant on range -