i am working on a python client for the api of uwsgi.it and i found the necessity to write methods that accept lots of (optional) parameters that will be sent via http requests.
Initially i wanted to declare which parameters the user can insert, since they are so many i thought it was easier, and safer, for the user to have a list as parameters instead of leave him free to insert anything inside a dict and i ended up with something like this:
def alarms(self, container=None, _class=None, color=None,
vassal=None, level=None, line=None, filename=None,
func=None, with_total=None, range=None):
params = {k: v for k, v in locals().iteritems() if k != 'self' and v}
if '_class' in params:
params['class'] = params['_class']
del params['_class']
return self.get('alarms', params)
But it is pretty ugly and i really don't like this way to handle '_class' parameter. So the other possibility that comes to my mind is to accept a dictionary that can contain anything (or **kwargs), list the accepted keys in the docstring and then to sanitize the input. A possible way would be to declare a "private" method that accept only the allowed params. But then the same problems appears again! Any suggestion? Any best-practice for methods with so many parameters?