# Python API

Topics

- Python API

  - Python API example

Note

This API is intended for internal Ansible use. Ansible may make changes to this API at any time that could break backward compatibility with older versions of the API. Because of this, external use is not supported by Ansible.

There are several ways to use Ansible from an API perspective. You can use the Ansible Python API to control nodes, you can extend Ansible to respond to various Python events, you can write plugins, and you can plug in inventory data from external data sources. This document gives a basic overview and examples of the Ansible execution and playbook API.

If you would like to use Ansible programmatically from a language other than Python, trigger events asynchronously, or have access control and logging demands, please see the Ansible Tower documentation.

Note

Because Ansible relies on forking processes, this API is not thread safe.

## Python API example

This example is a simple demonstration that shows how to minimally run a couple of tasks:

Note

Ansible emits warnings and errors via the display object, which prints directly to stdout, stderr and the Ansible log.

The source code for the `ansible` command line tools (`lib/ansible/cli/`) is available on GitHub.

See also

Developing dynamic inventory

  Developing dynamic inventory integrations

Ansible module development: getting started

  Getting started on developing a module

Developing plugins

  How to develop plugins

Development Mailing List

  Mailing list for development topics

irc.freenode.net

  #ansible IRC chat channel