Templates
A lot of the power from AutoAPI comes from templates. We are basically building a mapping from code to docs, and templates let you highly customise the display of said docs.
Structure
Every type of data structure has its own template.
It uses the form language/type.rst
to find the template to render.
The full search path is:
language/type.rst
So for a .NET Class, this would resolve to:
dotnet/class.rst
We provide base/base.rst
as an incredibly basic output of every object:
.. {language}:{type}:: {name}
Context
Every template is given a set context that can be accessed in the templates. This contains:
autoapi_options
: The value of theautoapi_options
configuration option.obj
: A Python object derived fromPythonMapperBase
.sphinx_version
: The contents ofsphinx.version_info
.
This object has a number of standard attributes you can reliably access per language.
Warning
These classes should not be constructed manually. They can be reliably accessed through templates only.
Python
- class autoapi.mappers.python.objects.PythonPythonMapper(obj, class_content='class', **kwargs)
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- inherited
Whether this was inherited from an ancestor of the parent class.
- Type:
bool
- is_callable = False
- language = python
- member_order = 0
- class autoapi.mappers.python.objects.PythonFunction(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonPythonMapper
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- is_callable = True
- member_order = 40
- overloads
The list of overloaded signatures
[(args, return_annotation), ...]
of this function.- Type:
list(tuple(str, str))
- properties
The properties that describe what type of function this is.
Can be only be: async
- Type:
list(str)
- return_annotation
The type annotation for the return type of this function.
This will be
None
if an annotation or annotation comment was not given.- Type:
str or None
- type = function
- class autoapi.mappers.python.objects.PythonMethod(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonFunction
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- is_callable = True
- member_order = 50
- method_type
The type of method that this object represents.
This can be one of: method, staticmethod, or classmethod.
- Type:
str
- properties
The properties that describe what type of method this is.
Can be any of: abstractmethod, async, classmethod, property, staticmethod
- Type:
list(str)
- type = method
- class autoapi.mappers.python.objects.PythonData(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonPythonMapper
Global, module level data.
- annotation
The type annotation of this attribute.
This will be
None
if an annotation or annotation comment was not given.- Type:
str or None
- member_order = 10
- type = data
- value
The value of this attribute.
This will be
None
if the value is not constant.- Type:
str or None
- class autoapi.mappers.python.objects.PythonAttribute(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonData
An object/class level attribute.
- member_order = 10
- type = attribute
- class autoapi.mappers.python.objects.TopLevelPythonPythonMapper(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonPythonMapper
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- all
The contents of
__all__
if assigned to.Only constants are included. This will be
None
if no__all__
was set.- Type:
list(str) or None
- top_level_object
Whether this object is at the very top level (True) or not (False).
This will be False for subpackages and submodules.
- Type:
bool
- class autoapi.mappers.python.objects.PythonModule(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.TopLevelPythonPythonMapper
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- type = module
- class autoapi.mappers.python.objects.PythonPackage(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.TopLevelPythonPythonMapper
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- type = package
- class autoapi.mappers.python.objects.PythonClass(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonPythonMapper
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- bases
The fully qualified names of all base classes.
- Type:
list(str)
- member_order = 30
- type = class
- class autoapi.mappers.python.objects.PythonException(obj, **kwargs)
Bases:
autoapi.mappers.python.objects.PythonClass
A base class for all types of representations of Python objects.
- Variables:
name (str) – The name given to this object.
id (str) – A unique identifier for this object.
children (list(PythonPythonMapper)) – The members of this object.
- member_order = 20
- type = exception
Go
- class autoapi.mappers.go.GoPythonMapper(obj, **kwargs)
Base object for JSON -> Python object mapping.
Subclasses of this object will handle their language specific JSON input, and map that onto this standard Python object. Subclasses may also include language-specific attributes on this object.
Arguments:
- Parameters:
obj – JSON object representing this object
jinja_env – A template environment for rendering this object
Required attributes:
- Variables:
id (str) – A globally unique indentifier for this object. Generally a fully qualified name, including namespace.
name (str) – A short “display friendly” name for this object.
Optional attributes:
- Variables:
docstring (str) – The documentation for this object
imports (list) – Imports in this object
children (list) – Children of this object
parameters (list) – Parameters to this object
methods (list) – Methods on this object
- inverted_names = False
- language = go
Javascript
- class autoapi.mappers.javascript.JavaScriptPythonMapper(obj, **kwargs)
Base object for JSON -> Python object mapping.
Subclasses of this object will handle their language specific JSON input, and map that onto this standard Python object. Subclasses may also include language-specific attributes on this object.
Arguments:
- Parameters:
obj – JSON object representing this object
jinja_env – A template environment for rendering this object
Required attributes:
- Variables:
id (str) – A globally unique indentifier for this object. Generally a fully qualified name, including namespace.
name (str) – A short “display friendly” name for this object.
Optional attributes:
- Variables:
docstring (str) – The documentation for this object
imports (list) – Imports in this object
children (list) – Children of this object
parameters (list) – Parameters to this object
methods (list) – Methods on this object
- language = javascript