import inspect

def foo(a, b, x='blah'):
    pass

print(inspect.signature(foo))
# (a, b, x='blah')

Python 3.5+ recommends inspect.signature().

Answer from unutbu on Stack Overflow
🌐
Python
docs.python.org › 3 › library › inspect.html
inspect — Inspect live objects
Pass False to get a signature of callable specifically (callable.__wrapped__ will not be used to unwrap decorated callables.) Changed in version 3.10: The globals, locals, and eval_str parameters were added. Changed in version 3.14: The annotation_format parameter was added. ... Some callables may not be introspectable in certain implementations of Python. For example, in CPython, some built-in functions defined in C provide no metadata about their arguments.
Discussions

Getting Function signature in CPython
As mentioned in other post I am ... signature. I’d like to know if i can expect an error before actually calling the function. How to get the Function signature in C-Python ? I have seen the inspect pack...... More on discuss.python.org
🌐 discuss.python.org
3
0
November 5, 2023
Using / and * in Python function signatures
Personally, I use keyword only when the parameter in question is "special" in some way and I want the usage more clear and also give me headroom to change the API later. Consider something like this: def create_pdf_report(foo, bar, *, debug=False) -> bytes Here, foo and bar are some parameters that will be used in the created PDF report, while the debug flag will cause a special PDF to be created which contains debug information (layout lines being drawn, boxes around paragraphs etc.) First, I don't want people to call the function as create_pdf_report(some_data, some_more_data, True) because it's not clear what Truemeans in this case, you'd have to check the signature of the create_pdf_report function to figure out it turns on debugging. create_pdf_report(some_data, some_more_data, debug=True) makes it obvious, even to someone not familiar with the API, that this is a report with some debugging info which should probably not make it into production. Another advantage is that in the future, if the API ever needs to change and a third parameter is added: create_pdf_report(foo, bar, baz, *, debug=True), old code will definitely raise an exception, while without keyword-only, create_pdf_report(data, more_data, True) will not, especially not if baz happens to be a boolean parameter. I've never used positional-only args. I know what they are for, I just never felt it necessary. More on reddit.com
🌐 r/learnpython
4
1
August 2, 2024
Helping people understand function signature syntax - Documentation - Discussions on Python.org
(Bringing a conversation about how to explain slash and star in function signatures from another post which talked about using tags, and a GitHub issue which experimented with tabs to show simplified vs complete signatures). Another possibility is to add a “help” icon next to signatures. More on discuss.python.org
🌐 discuss.python.org
9
July 20, 2024
Is there a way to check a function's signature in Python? - Stack Overflow
I'm looking for a way to check the number of arguments that a given function takes in Python. The purpose is to achieve a more robust method of patching my classes for tests. So, I want to do som... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-function-signature
Get Function Signature - Python - GeeksforGeeks
July 15, 2025 - inspect module offers a function called signature() that allows us to get the signature of any callable object in Python.
🌐
Readthedocs
python-forge.readthedocs.io › en › latest › signature.html
Signatures, parameters and return types — forge 18.6.0 documentation
forge.findparam() is a utility function for finding inspect.Parameter instances or FParameter instances in an iterable of parameters. The selector argument must be a string, an iterbale of strings, or a callable that recieves a parameter and conditionally returns True if the parameter is a match. This is helpful when copying matching elements from a signature.
🌐
Delft Stack
delftstack.com › home › howto › python › python function signature
How to Get Function Signature | Delft Stack
March 11, 2025 - This tutorial explores how to get function signatures in Python, providing clear methods and examples for understanding function call details. Learn to use the inspect module, __doc__ attribute, and help function to retrieve valuable information about functions.
🌐
TutorialsPoint
tutorialspoint.com › python-get-function-signature
Python - Get Function Signature
July 18, 2023 - Understanding function signatures in Python is essential for analyzing function parameters, data types, and default values. The inspect module provides powerful methods like signature() and getfullargspec() to retrieve detailed function information programmatically.
🌐
AskPython
askpython.com › home › understanding and utilizing function signatures in python
Understanding and Utilizing Function Signatures in Python - AskPython
June 30, 2023 - The signature() function from the inspect module is used to determine the function signature, helping developers to ensure they are passing the correct types of arguments to their functions.
Find elsewhere
🌐
Python.org
discuss.python.org › python help
Getting Function signature in CPython - Python Help - Discussions on Python.org
November 5, 2023 - Sorry for writing again, I did not manage to find out myself. As mentioned in other post I am using embedded python and I am calling python functions from within C . I am able to call the function with PyObject_CallO…
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module2_EssentialsOfPython › Functions.html
Basics of Functions — Python Like You Mean It
The following is the general syntax for defining a Python function: def <function name>(<function signature>): """ documentation string """ <encapsulated code> return <object>
🌐
Real Python
realpython.com › lessons › view-function-signatures
View Function Signatures (Video) – Real Python
... 00:05 When you type an opening parenthesis to call a function or method in bpython, it will display the corresponding function signature with its formal parameters and their default values.
Published   October 31, 2023
🌐
Python
peps.python.org › pep-0362
PEP 362 – Function Signature Object | peps.python.org
August 21, 2006 - The implementation adds a new function signature() to the inspect module. The function is the preferred way of getting a Signature for a callable object.
🌐
Reddit
reddit.com › r/learnpython › using / and * in python function signatures
r/learnpython on Reddit: Using / and * in Python function signatures
August 2, 2024 -

Hi everyone,

I've been exploring the use of / and * in Python function signatures to specify positional-only and keyword-only arguments. I understand the syntax, but I'm curious about their practical implications and best practices. I am coding for more than two years now and have never used them myself and i see them really rarely. That's why would like to learn about others experiance and maybe get some advice when it is appropriate to use them in my own functions?

Looking forward to your insights! Thanks!

Top answer
1 of 2
5
Personally, I use keyword only when the parameter in question is "special" in some way and I want the usage more clear and also give me headroom to change the API later. Consider something like this: def create_pdf_report(foo, bar, *, debug=False) -> bytes Here, foo and bar are some parameters that will be used in the created PDF report, while the debug flag will cause a special PDF to be created which contains debug information (layout lines being drawn, boxes around paragraphs etc.) First, I don't want people to call the function as create_pdf_report(some_data, some_more_data, True) because it's not clear what Truemeans in this case, you'd have to check the signature of the create_pdf_report function to figure out it turns on debugging. create_pdf_report(some_data, some_more_data, debug=True) makes it obvious, even to someone not familiar with the API, that this is a report with some debugging info which should probably not make it into production. Another advantage is that in the future, if the API ever needs to change and a third parameter is added: create_pdf_report(foo, bar, baz, *, debug=True), old code will definitely raise an exception, while without keyword-only, create_pdf_report(data, more_data, True) will not, especially not if baz happens to be a boolean parameter. I've never used positional-only args. I know what they are for, I just never felt it necessary.
2 of 2
2
From a module standpoint (disclaimer: I have no experience writing modules - this is mostly speculation and regurgitation from memory), it's useful for providing a consistent API. Positional-only is useful for defining an interface when the library is written in C or similar (or even if you've just picked parameter names that might change). I believe that Python functions written in C can only accept positional arguments (I think PEP 570 explains it well). Keyword-only can make modules more flexible for backwards compatibility. By ensuring that arguments can only be passed by name, it makes the interface consistent (otherwise you've got two options for calling) and probably makes it easier to add or deprecate arguments
🌐
YouTube
youtube.com › watch
[Python] How to get function signature - YouTube
How to get function signature in PythonText article: http://wordpress.jmcgowan.com/wp/python-how-to-get-function-signature/About Us:Main Web Site: https://ma...
Published   September 20, 2022
🌐
Python.org
discuss.python.org › documentation
Helping people understand function signature syntax - Documentation - Discussions on Python.org
July 20, 2024 - (Bringing a conversation about how to explain slash and star in function signatures from another post which talked about using <abbr> tags, and a GitHub issue which experimented with tabs to show simplified vs complete s…
🌐
Smarie
smarie.github.io › python-makefun
makefun
Note that Signature objects do not contain any function name information. You therefore have to provide an explicit func_name argument to @with_signature (or to create_function) as shown above. ... In python 2 the inspect package does not provide any signature-related features, but a complete backport is available: funcsigs.
🌐
IPython
ipython.org › ipython-doc › 3 › api › generated › IPython.utils.signatures.html
Module: utils.signatures — IPython 3.2.1 documentation
If the function has no annotation for its return type, this attribute is not set. __init__(parameters=None, return_annotation=<class 'IPython.utils.signatures._empty'>, __validate_parameters__=True)¶ · Constructs Signature from the given list of Parameter objects and ‘return_annotation’. All arguments are optional. ... Get a BoundArguments object, that maps the passed args and kwargs to the function’s signature.
🌐
Readthedocs
funcsigs.readthedocs.io › en › 0.4
Introducing funcsigs — funcsigs 0.4 documentation
PEP 362 - Function Signature Object. The detailed specification, implementation details and examples. funcsigs is a derived work of CPython under the terms of the PSF License Agreement. The original CPython inspect module, its unit tests and documentation are the copyright of the Python Software Foundation.
🌐
Gaohongnan
gaohongnan.com › playbook › how_to_inspect_function_and_class_signatures.html
How to Inspect Function and Class Signatures in Python? — Omniverse
Our initial goal is to get all signatures and type annotations of a class or function. We can use the inspect module to achieve this. The getmembers function returns all members of a class or module.
🌐
pytz
pythonhosted.org › sigtools
sigtools documentation — sigtools 0.1a2 documentation
Python 3.3’s inspect module has ... call signature. This package helps module authors enhance their callables’ introspectability if needed, for instance for documentation, and provides a way to use features the python syntax does not or did not permit, such as keyword-only parameters. For versions of Python below 3.3, a backport of the relevant parts of inspect is available on pypi. The functions in this module ...