How to Pass a Dictionary as Keyword Arguments in Python with ** (Double Star)
When a function's arguments are already in a dictionary, such as settings read from a file, ** passes them all at once: each key becomes a keyword argument with its value. This guide spreads a dictionary into a function call on Python 3.15.2.
Syntax
<function>(**<dictionary>)
| Part | What it means |
|---|---|
** | Unpacks the dictionary into keyword arguments |
<dictionary> | Keys that match the function's parameter names, with the values to pass |
The Python language reference says: "If the syntax **expression appears in the function call, expression must evaluate to a mapping, the contents of which are treated as additional keyword arguments."
The Example
describe takes a bike's name, colour and number of gears. The bike is stored as a dictionary with those three keys.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
def describe(name, colour, gears):
return f"{name}: {colour}, {gears} gears"
bike = {"name": "City", "colour": "blue", "gears": 7}
print(describe(**bike))

Step 2: Run It
uv run python describe.py
City: blue, 7 gears

describe(**bike) worked as describe(name="City", colour="blue", gears=7): each key matched the parameter of the same name. The command works unchanged in PowerShell.
Mixing ** with Other Arguments
You can pass some values from a dictionary and the rest by hand. describe(**{"name": "City", "colour": "blue"}, gears=7) printed the same line.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A key the function doesn't take, such as "price" | TypeError: describe() got an unexpected keyword argument 'price' | Keep only the keys the function names, or add the parameter |
A missing key, such as no "gears" | TypeError: describe() missing 1 required positional argument: 'gears' | Add the key, or give the parameter a default |
One star instead of two: describe(*bike) | A single * passes the dictionary's keys, not its values: it printed name: colour, gears gears | Use ** for keyword arguments |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
got an unexpected keyword argument '<key>' | The dictionary has a key with no matching parameter | Remove the key or rename it |
missing 1 required positional argument: '<name>' | A parameter has no matching key | Add the key to the dictionary |
FAQ
Does the order of the keys matter?
No. Each value goes to the parameter with the same name as its key, wherever the key is in the dictionary.
Can I use it with classes too?
Yes, anything you call. HistGradientBoostingRegressor(**settings) passes a dictionary of settings to a scikit-learn model the same way.
Conclusion
describe(**bike) turned the dictionary's three keys into the three keyword arguments describe needs. The keys must match the parameter names exactly, with none extra and none missing.
Additional Resources
- Calls — the language reference on
*and**in calls. - Unpacking Argument Lists — the Python tutorial.
