Pythonic way of getting method arguments into a dict
<p>I'm writing an api and was wondering what's the most pythonic way to do the following.</p>

<p>I'm writing a bunch of methods to do various web calls, the arguments mostly translate into post data keys and values.</p>

<p>The way I've been writing it so far is mostly like this;</p>

<pre><code>def doSomething(self,param1,param2,param3):
    payload={"param1":param1,
             "param2":param2,
             "param3":param3}
    return self.request("do/something",payload)
</code></pre>

<p>This already has the draw back of having to repeat the parameter names which are subject to change, but this pattern isn't too bad.</p>

<p>The following case is what got me trying to think of a better way. In this case there are 4 optional arguments for the call</p>

<pre><code>def doSomethingElse(self,param1,param2=None,param3=None,param4=None,param5=None):
    payload= {"param1":param1}
    if param2:
        payload["param2"]= param2
    if param3:
        payload["param3"]= param3
    # ... etc ...
    self.request("do/something/else",payload)
</code></pre>

<p>My first thought was to do this:</p>

<pre><code>def doSomethingElse(self,param1,**params):
    payload = {"param1":param1}
    payload.update(params)
    self.request("do/something/else",payload)
</code></pre>

<p>or even:</p>

<pre><code>def doSomethingElse(self,**payload):
    self.request("do/something/else",payload)
</code></pre>

<p>Although the second one is nice and simple, the method can be called without the non-default argument. But in both cases I lose the method signature when using the api and the user won't know what the parameters are (I know I could write the expected signature in a docstring but I'd rather prevent misspelt keywords getting sent).</p>

<p>I'm thinking there must be a nice pythonic solution to do this, any ideas?</p>

<h2>EDIT</h2>

<p>I think a key point which I didn't make clear enough is that the arguments are getting sent in  post data in a call, and I want to make sure only those keys can get sent, like in the first example of <code>doSomethingElse</code>, you can't send anything other than those 5 named parameters.</p>
