PyDocs

Python Runtime Services

inspect

Get useful information from live Python objects.

This module encapsulates the interface provided by the internal special
attributes (co_*, tb_*, etc.) in a friendlier fashion.
It also provides some help for examining source code and class layout.

Here are some of the useful functions provided by this module:

    ismodule(), isclass(), ismethod(), ispackage(), isfunction(),
        isgeneratorfunction(), isgenerator(), istraceback(), isframe(),
        iscode(), isbuiltin(), isroutine() - check object types
    getmembers() - get members of an object that satisfy a given condition

    getfile(), getsourcefile(), getsource() - find an object's source code
    getdoc(), getcomments() - get documentation on an object
    getmodule() - determine the module that an object came from
    getclasstree() - arrange classes so as to represent their hierarchy

    getargvalues(), getcallargs() - get info about function arguments
    getfullargspec() - same, with support for Python 3 features
    formatargvalues() - format an argument spec
    getouterframes(), getinnerframes() - get info about frames
    currentframe() - get the current stack frame
    stack(), trace() - get info about frames on the stack or in a traceback

    signature() - get a Signature object for the callable
Symbols in inspect

b

BoundArguments
Result of `Signature.bind` call.
BufferFlags
This is an enum.IntFlag that represents the flags that can be passed to the __buffer__() method of objects implementing the buffer protocol.

c

cleandoc
Clean up indentation from docstrings.
CO_ASYNC_GENERATOR
The flag is set when the code object is an asynchronous generator function.
CO_COROUTINE
The flag is set when the code object is a coroutine function.
CO_GENERATOR
The flag is set when the code object is a generator function, i.e.
CO_HAS_DOCSTRING
The flag is set when there is a docstring for the code object in the source code.
CO_ITERABLE_COROUTINE
The flag is used to transform generators into generator-based coroutines.
CO_METHOD
The flag is set when the code object is a function defined in class scope.
CO_NESTED
The flag is set when the code object is a nested function.
CO_NEWLOCALS
If set, a new dict will be created for the frame’s f_locals when the code object is executed.
CO_OPTIMIZED
The code object is optimized, using fast locals.
CO_VARARGS
The code object has a variable positional parameter (*args-like).
CO_VARKEYWORDS
The code object has a variable keyword parameter (**kwargs-like).
currentframe
Return the frame of the caller or None if this is not possible.

f

formatargvalues
Format an argument spec from the 4 values returned by getargvalues.
FrameInfo
Changed in version 3.5: Return a named tuple instead of a tuple.

g

get_annotations
Compute the annotations dict for an object.
getargvalues
Get information about arguments passed into a particular frame.
getasyncgenlocals
Get the mapping of asynchronous generator local variables to their current values.
getasyncgenstate
Get current state of an asynchronous generator object.
getattr_static
Retrieve attributes without triggering dynamic lookup via the descriptor protocol, __getattr__ or __getattribute__.
getcallargs
Get the mapping of arguments to values.
getclasstree
Arrange the given list of classes into a hierarchy of nested lists.
getclosurevars
Get the mapping of free variables to their current values.
getcomments
Get lines of comments immediately preceding an object's source code.
getcoroutinelocals
Get the mapping of coroutine local variables to their current values.
getcoroutinestate
Get current state of a coroutine object.
getdoc
Get the documentation string for an object.
getfile
Work out which source or compiled file an object was defined in.
getframeinfo
Get information about a frame or traceback object.
getfullargspec
Get the names and default values of a callable object's parameters.
getgeneratorlocals
Get the mapping of generator local variables to their current values.
getgeneratorstate
Get current state of a generator-iterator.
getinnerframes
Get a list of records for a traceback's frame and all lower frames.
getmembers
Return all members of an object as (name, value) pairs sorted by name.
getmembers_static
Return all members of an object as (name, value) pairs sorted by name without triggering dynamic lookup via the descriptor protocol, __getattr__ or __getattribute__.
getmodule
Return the module an object was defined in, or None if not found.
getmodulename
Return the module name for a given file, or None.
getmro
Return tuple of base classes (including cls) in method resolution order.
getouterframes
Get a list of records for a frame and all higher (calling) frames.
getsource
Return the text of the source code for an object.
getsourcefile
Return the filename that can be used to locate an object's source.
getsourcelines
Return a list of source lines and starting line number for an object.

i

isabstract
Return true if the object is an abstract base class (ABC).
isasyncgen
Return true if the object is an asynchronous generator.
isasyncgenfunction
Return true if the object is an asynchronous generator function.
isawaitable
Return true if object can be passed to an ``await`` expression.
isbuiltin
Return true if the object is a built-in function or method.
isclass
Return true if the object is a class.
iscode
Return true if the object is a code object.
iscoroutine
Return true if the object is a coroutine.
iscoroutinefunction
Return true if the object is a coroutine function.
isdatadescriptor
Return true if the object is a data descriptor.
isframe
Return true if the object is a frame object.
isfunction
Return true if the object is a user-defined function.
isgenerator
Return true if the object is a generator.
isgeneratorfunction
Return true if the object is a user-defined generator function.
isgetsetdescriptor
Return true if the object is a getset descriptor.
ismemberdescriptor
Return true if the object is a member descriptor.
ismethod
Return true if the object is an instance method.
ismethoddescriptor
Return true if the object is a method descriptor.
ismethodwrapper
Return true if the object is a method wrapper.
ismodule
Return true if the object is a module.
ispackage
Return true if the object is a package.
isroutine
Return true if the object is any kind of function or method.
istraceback
Return true if the object is a traceback.

m

markcoroutinefunction
Decorator to ensure callable is recognised as a coroutine function.

p

Parameter
Represents a parameter in a function signature.

s

signature
Get a signature object for the passed callable.
Signature
A Signature object represents the overall signature of a function.
stack
Return a list of records for the stack above the caller's frame.

t

trace
Return a list of records for the stack below the current exception.
Traceback
Changed in version 3.11: Traceback is now a class instance (that is backwards compatible with the previous named tuple).

u

unwrap
Get the object wrapped by *func*.