You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/index.rst
+61-1Lines changed: 61 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,64 @@ Using the API
3
3
4
4
In addition to :doc:`the pyinfra CLI <../cli>`, pyinfra provides a full Python API. As of ``v3`` this API can be considered mostly stable. See the :doc:`./reference`.
5
5
6
-
`An example of how to use the API can be found here <https://github.com/pyinfra-dev/pyinfra-examples/blob/main/.old/api_deploy.py>`_. Note: this is not yet tested and pending future updates.
6
+
You can also reference `pyinfra's own main.py <https://github.com/pyinfra-dev/pyinfra/blob/3.x/pyinfra_cli/main.py>`_, and the `pyinfra API source code <https://github.com/pyinfra-dev/pyinfra/tree/3.x/pyinfra/api>`_.
7
+
8
+
Full Example
9
+
============
10
+
11
+
`A full example of how to use the API can be found here <https://github.com/pyinfra-dev/pyinfra-examples/blob/main/.old/api_deploy.py>`_. (Note: this is not yet tested and is pending future updates)
12
+
13
+
Basic Localhost Example
14
+
=======================
15
+
16
+
.. code:: python
17
+
18
+
from pyinfra.api import Config, Inventory, State
19
+
from pyinfra.api.connect import connect_all
20
+
from pyinfra.api.operation import add_op
21
+
from pyinfra.api.operations import run_ops
22
+
from pyinfra.api.facts import get_facts
23
+
from pyinfra.facts.server import Os
24
+
from pyinfra.operations import server
25
+
26
+
# Define your inventory (@local means execute on localhost using subprocess)
0 commit comments