Well we don't actually need inspect here.

>>> func = lambda x, y: (x, y)
>>> 
>>> func.__code__.co_argcount
2
>>> func.__code__.co_varnames
('x', 'y')
>>>
>>> def func2(x,y=3):
...  print(func2.__code__.co_varnames)
...  pass # Other things
... 
>>> func2(3,3)
('x', 'y')
>>> 
>>> func2.__defaults__
(3,)
Answer from simplyharsh on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-list-of-parameters-name-from-a-function-in-python
How to get list of parameters name from a function in Python? - GeeksforGeeks
July 23, 2025 - It supports positional, keyword-only and default arguments, making it suitable for detailed function analysis. ... import inspect def fun(a, b, c=10): pass res = list(inspect.signature(fun).parameters.keys()) print(res) ... Explanation: inspect.signature(fun).parameters returns an ordered mapping of parameter names and extracting .keys() converts them into a list. inspect.getfullargspec() retrieves a function's parameter names along with details like default values and annotations.
Discussions

Getting all arguments from a function call in python
If you for some reason want to get a list of all the arguments, but you don't want to have a variable amount with *args and **kwargs, then you can save the locals at the beginning of the function and use that. Example: >>> def test(a, b, c): ... args = locals() ... print(args) ... >>> test(1, 2, 3) {'a': 1, 'b': 2, 'c': 3} More on reddit.com
🌐 r/learnpython
13
3
May 23, 2021
Get exact function call keyword arguments in order
I have a function with keyword-only parameters. In the function, the function needs access to the keyword arguments passed into it, in the order they were listed on the call site, and only those which were passed in. de… More on discuss.python.org
🌐 discuss.python.org
11
0
November 7, 2023
python - Getting all arguments and values passed to a function - Stack Overflow
I have a Python function, fetch_data, that goes and hits a remote API, grabs some data, and returns it wrapped in a response object. It looks a bit like the below: def fetch_data(self, foo, bar, b... More on stackoverflow.com
🌐 stackoverflow.com
June 2, 2014
Get names of positional arguments in wrapping function
Imagine this made-up decorator that tries to capture the arguments of the wrapped function and save them to some key-value store for logging purposes: import json from functools import wraps some_path = ... def log_args_to_json(func): @wraps(func) def wrapper(*args, **kwargs): # What to do ... More on discuss.python.org
🌐 discuss.python.org
5
0
August 19, 2024
🌐
Python.org
discuss.python.org › python help
Some way to get arguments of current function for passing along to another function even when not using *args/**kw - Python Help - Discussions on Python.org
June 10, 2024 - Often times I have a function that does not make use of *args/**kw for various reasons but still needs to pass along all arguments to another function. An example would be: def other_fun(a, b, c=7, d=9): ... def myfun(a, b, c=7, d=9): v = other_fun(a, b, c=c, d=d) # do some other post processing of v, often times depending on the input arguments ...
🌐
LabEx
labex.io › tutorials › python-how-to-retrieve-python-function-arguments-466063
How to retrieve Python function arguments | LabEx
This tutorial provides comprehensive insights into examining function parameters, exploring introspection techniques, and implementing practical argument handling strategies that can enhance code flexibility and debugging capabilities. In Python, function arguments are a fundamental concept that allows you to pass data into functions.
🌐
Programiz
programiz.com › python-programming › function-argument
Python Function Arguments (With Examples)
Here, we are able to call the same function with different arguments. Note: After getting multiple values, numbers behave as an array so we are able to use the for loop to access each value.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-get-all-arguments-passed-to-function
Get all arguments passed to a Function in Python | bobbyhadz
Use the `locals()` function to get all arguments passed to a function, e.g. `all_arguments = locals()`.
Find elsewhere
🌐
Bradley Schacht
bradleyschacht.com › list-parameters-for-a-python-function
List Parameters for a Python Function
May 24, 2024 - The inspect module can help get some useful information for us in this case as well. Using my new friend help, I can see this will give me a look at useful information from Python objects. Here we will look at two functions: inspect.signature() and inspect.getfullargspec().
🌐
W3Schools
w3schools.com › python › python_arguments.asp
Python Function Arguments
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... Information can be passed into functions as arguments.
🌐
Python.org
discuss.python.org › python help
Get exact function call keyword arguments in order - Python Help - Discussions on Python.org
November 7, 2023 - I have a function with keyword-only parameters. In the function, the function needs access to the keyword arguments passed into it, in the order they were listed on the call site, and only those which were passed in. def func(p0=0, p1=1): callDict = getcallargumentsonly(perhapsCurrentFrame) ... func(p1=2) I looked at inspect.getargvalues(inspect.currentframe()) but it returns the complete dictionary of parameters, eg. p0 and p1 whereas I would like a way to see that only p1 was passed in...
Top answer
1 of 11
184

Essentially, I'm trying to work out how to, from within a function, get a completely populated *args and **kwargs, including the function's named parameters.

How about saving the arguments via locals() at the beginning of the function?

def my_func(a, *args, **kwargs):
    saved_args = {**locals()}  # Updated to make a copy per loco.loop
    print("saved_args is", saved_args)
    local_var = 10
    print("saved_args is", saved_args)
    print("But locals() is now", locals())
    
my_func(20, 30, 40, 50, kwarg1='spam', kwarg2='eggs')

It gives this output:

saved_args is {'a': 20, 'args': (30, 40, 50), 'kwargs': {'kwarg1': u'spam', 'kwarg2': u'eggs'}}
saved_args is {'a': 20, 'args': (30, 40, 50), 'kwargs': {'kwarg1': u'spam', 'kwarg2': u'eggs'}}
But locals is now {'a': 20, 'saved_args': {...}, 'args': (30, 40, 50), 'local_var': 10, 'kwargs': {'kwarg1': u'spam', 'kwarg2': u'eggs'}}

Hat tip: https://stackoverflow.com/a/3137022/2829764

2 of 11
58

Not something I'd do, but you could use inspect.signature to introspect the arguments your method takes:

>>> import inspect
>>> def foobar(foo, bar, baz):
...     return inspect.signature(foobar)
... 
>>> foobar(1, 2, 3)
<Signature (foo, bar, baz)>

The returned Signature instance has an ordered collection of parameters (the .parameters attribute) which can then be used together with locals() to produce a list of your argument values:

>>> def foobar(foo, bar, baz):
...     sig, foobar_locals = inspect.signature(foobar), locals()
...     return [foobar_locals[param.name] for param in sig.parameters.values()]
...
>>> foobar(1, 2, 3)
[1, 2, 3]

However, you really only need such magic when doing advanced function decorators and the like. I think it's overkill here.

🌐
KDnuggets
kdnuggets.com › 2023 › 02 › python-function-arguments-definitive-guide.html
Python Function Arguments: A Definitive Guide - KDnuggets
February 9, 2023 - To define a Python function, you can use the def keyword followed by the name of the function in parentheses. If you’d like the function to take in arguments, then the names of the arguments should be specified as parameters inside parentheses.
🌐
Python
docs.python.org › 3.3 › library › inspect.html
28.12. inspect — Inspect live objects — Python 3.3.7 documentation
December 18, 2019 - Deprecated since version 3.0: Use getfullargspec() instead, which provides information about keyword-only arguments and annotations. ... Get the names and default values of a Python function’s arguments.
🌐
LabEx
labex.io › tutorials › python-how-to-get-function-argument-details-466056
How to get function argument details | LabEx
The inspect module offers comprehensive tools for function argument analysis: import inspect def example_function(a, b=10, *args, **kwargs): pass ## Get function signature signature = inspect.signature(example_function) print(signature) ## Detailed ...
🌐
Python.org
discuss.python.org › python help
Get names of positional arguments in wrapping function - Python Help - Discussions on Python.org
August 19, 2024 - Imagine this made-up decorator that tries to capture the arguments of the wrapped function and save them to some key-value store for logging purposes: import json from functools import wraps some_path = ... def log_args_to_json(func): @wraps(func) def wrapper(*args, **kwargs): # What to do with the args? data = json.dumps("func_name": func.__name__, "kwargs": kwargs) some_path.write_text(data) return func(*args, **kwargs) return wrapper @log_args...
Top answer
1 of 1
42

You can use inspect.getargspec() to see what arguments are accepted, and any default values for keyword arguments.

Demo:

>>> def foo(bar, baz, spam='eggs', **kw): pass
... 
>>> import inspect
>>> inspect.getargspec(foo)
ArgSpec(args=['bar', 'baz', 'spam'], varargs=None, keywords='kw', defaults=('eggs',))
>>> inspect.getargspec(foo).args
['bar', 'baz', 'spam']

In Python 3, you want to use inspect.getfullargspec() as this method supports new Python 3 function argument features:

>>> def foo(bar: str, baz: list, spam: str = 'eggs', *, monty: str = 'python', **kw) -> None: pass
... 
>>> import inspect
>>> inspect.getfullargspec(foo)
FullArgSpec(args=['bar', 'baz', 'spam'], varargs=None, varkw='kw', defaults=('eggs',), kwonlyargs=['monty'], kwonlydefaults={'monty': 'python'}, annotations={'baz': <class 'list'>, 'return': None, 'spam': <class 'str'>, 'monty': <class 'str'>, 'bar': <class 'str'>})

inspect.getargspec() should be considered deprecated in Python 3.

Python 3.4 adds the inspect.Signature() object:

>>> inspect.signature(foo)
<inspect.Signature object at 0x100bda588>
>>> str(inspect.signature(foo))
"(bar:str, baz:list, spam:str='eggs', *, monty:str='python', **kw) -> None"
>>> inspect.signature(foo).parameters
mappingproxy(OrderedDict([('bar', <Parameter at 0x100bd67c8 'bar'>), ('baz', <Parameter at 0x100bd6ea8 'baz'>), ('spam', <Parameter at 0x100bd69f8 'spam'>), ('monty', <Parameter at 0x100bd6c28 'monty'>), ('kw', <Parameter at 0x100bd6548 'kw'>)]))

and many more interesting options to play with signatures.

🌐
YouTube
youtube.com › watch
How to Retrieve Function Input Argument Names in Python - YouTube
Discover how to extract input argument names in Python functions with practical examples and solutions.---This video is based on the question https://stackov...
Published: May 26, 2025
Views: 2
🌐
PYnative
pynative.com › home › python › basics › python function arguments
Python Function Arguments [4 Types] – PYnative
August 2, 2022 - Keyword arguments passed to a kwargs are accessed using key-value pair (same as accessing a dictionary in Python). ... # function with variable-length keyword arguments def percentage(**kwargs): sum = 0 for sub in kwargs: # get argument name sub_name = sub # get argument value sub_marks = kwargs[sub] print(sub_name, "=", sub_marks) # pass multiple keyword arguments percentage(math=56, english=61, science=73)Code language: Python (python) Run