Scott S. Lowe 9ddefb93f7
Standardize language aliases (#3350)
Ensure language aliases exist for all languages.
Standardize existing language aliases for consistency.

Signed-off-by: Scott Lowe <slowe@pulumi.com>
2023-09-08 15:59:37 -06:00

4.6 KiB

title_tag, meta_desc, title, h1, meta_image, menu, aliases
title_tag meta_desc title h1 meta_image menu aliases
Python | Languages & SDKs An overview of how to use Python with Pulumi for infrastructure as code on any cloud (AWS, Azure, Google Cloud, Kubernetes, etc.). Python Pulumi & Python /images/docs/meta-images/docs-meta.png
languages
identifier weight
python 2
/docs/reference/python/
/docs/intro/languages/python/
/python/

Pulumi supports writing your infrastructure as code in the Python language running on any supported version.

{{< install-python >}}

Pulumi Programming Model

The Pulumi programming model defines the core concepts you will use when creating infrastructure as code programs using Pulumi. Concepts describes these concepts with examples available in Python. These concepts are made available to you in the Pulumi SDK.

The Pulumi SDK is available to Python developers as a Pip package distributed on PyPI. To learn more, refer to the Pulumi SDK Reference Guide.

The Pulumi programming model includes a core concept of Input and Output values, which are used to track how outputs of one resource flow in as inputs to another resource. This concept is important to understand when getting started with Python and Pulumi, and the Inputs and Outputs documentation is recommended to get a feel for how to work with this core part of Pulumi in common cases.

Using Pulumi PyPI Packages

Virtual Environments

It is not required, but we recommend using a virtual environment to isolate the dependencies of your projects and ensure reproducibility between machines.

As of Pulumi 2.4.0, new Python projects created with pulumi new will have a virtual environment created in a venv directory with required dependencies from requirements.txt installed in it, and Pulumi will automatically use this virtual environment when running the program.

This behavior is controlled by the following virtualenv runtime option in Pulumi.yaml:

runtime:
  name: python
  options:
    virtualenv: venv

virtualenv is the path to a virtual environment to use.

Existing Python projects can opt-in to using the built-in virtual environment support by setting the virtualenv option. To manually create a virtual environment and install dependencies, run the following commands in your project directory:

{{< chooser os "macos,windows,linux" >}}

{{% choosable os macos %}}

$ python3 -m venv venv
$ venv/bin/pip install -r requirements.txt

{{% /choosable %}}

{{% choosable os linux %}}

$ python3 -m venv venv
$ venv/bin/pip install -r requirements.txt

{{% /choosable %}}

{{% choosable os windows %}}

> python -m venv venv
> venv\Scripts\pip install -r requirements.txt

{{% /choosable %}}

{{< /chooser >}}

If you prefer to manage the virtual environment on your own (for example, using a tool like Pipenv), you can delete the local venv directory and unset the virtualenv option in Pulumi.yaml:

runtime: python

When managing the virtual environment on your own, you'll need to run any pulumi commands (such as pulumi up) from an activated virtual environment shell (or, if using a tool like Pipenv, prefix any pulumi commands with pipenv run pulumi ...).

Adding a new dependency

There are many Pulumi Python packages available.

To install a new dependency in the virtual environment, add an entry to requirements.txt, and run the following in your project directory:

{{< chooser os "macos,windows,linux" >}}

{{% choosable os macos %}}

$ venv/bin/pip install -r requirements.txt

{{% /choosable %}}

{{% choosable os linux %}}

$ venv/bin/pip install -r requirements.txt

{{% /choosable %}}

{{% choosable os windows %}}

> venv\Scripts\pip install -r requirements.txt

{{% /choosable %}}

{{< /chooser >}}

Package Documentation

In addition to the standard packages the Pulumi Registry houses 100+ Python packages.

Standard Packages

Pulumi SDK
pulumi
Pulumi Policy
pulumi_policy
Pulumi Terraform
pulumi_terraform