{"id":179,"library":"pulumi","title":"Pulumi Python SDK","description":"Infrastructure as Code SDK for Python. Current version: 3.227.0 (Mar 2026). Requires Pulumi CLI installed separately — 'pip install pulumi' alone does nothing useful. All resource properties return Output[T] not plain values — cannot use them directly as strings/ints. Must use .apply() or Output.all() to work with output values. pulumi.export() must be at top level, not inside apply(). CLI and SDK versions should be kept in sync.","status":"active","version":"3.227.0","language":"python","source_language":"en","source_url":"https://github.com/pulumi/pulumi","tags":["pulumi","iac","infrastructure","python","devops","aws","azure","gcp"],"install":[{"cmd":"pip install pulumi","lang":"bash","label":"Python SDK (also requires Pulumi CLI)"},{"cmd":"curl -fsSL https://get.pulumi.com | sh","lang":"bash","label":"Pulumi CLI (required — install separately)"}],"dependencies":[{"reason":"Required for AWS resources. Install separately: pip install pulumi-aws","package":"pulumi-aws","optional":true},{"reason":"Required for Azure resources. Install separately: pip install pulumi-azure-native","package":"pulumi-azure-native","optional":true},{"reason":"Required for GCP resources. Install separately: pip install pulumi-gcp","package":"pulumi-gcp","optional":true}],"imports":[{"note":"Resource outputs are Output[T] — lazy futures resolved during pulumi up. Cannot use them as plain values. Must use .apply() to access the inner value. pulumi.export() only works at top level.","wrong":"import pulumi_aws as aws\n\nbucket = aws.s3.Bucket('my-bucket')\n\n# Wrong: bucket.bucket is Output[str] not str\nprint(f'Bucket: {bucket.bucket}')  # prints <pulumi.output.Output>\n\n# Wrong: export inside apply\nbucket.bucket.apply(lambda name: pulumi.export('name', name))  # ignored","symbol":"Output / apply","correct":"import pulumi\nimport pulumi_aws as aws\n\nbucket = aws.s3.Bucket('my-bucket')\n\n# Output values must be accessed via .apply()\nbucket.bucket.apply(lambda name: print(f'Bucket name: {name}'))\n\n# Combine multiple outputs with Output.all()\npulumi.Output.all(bucket.bucket, bucket.region).apply(\n    lambda args: print(f'Bucket {args[0]} in {args[1]}')\n)\n\n# Export at TOP LEVEL — not inside apply()\npulumi.export('bucket_name', bucket.bucket)\npulumi.export('bucket_arn', bucket.arn)"},{"note":"pulumi.export() must be called at the top level of your Pulumi program, not inside functions, apply() callbacks, or conditional blocks.","wrong":"# Wrong: export inside a function called during up\ndef setup():\n    bucket = aws.s3.Bucket('b')\n    pulumi.export('name', bucket.bucket)  # may not be registered\n\nsetup()","symbol":"pulumi.export","correct":"import pulumi\nimport pulumi_aws as aws\n\n# Stack outputs — must be at top level of __main__.py\nbucket = aws.s3.Bucket('my-bucket', acl='private')\n\n# Export Output directly — Pulumi resolves it\npulumi.export('bucket_name', bucket.bucket)\npulumi.export('bucket_arn', bucket.arn)\n\n# Export transformed output\npulumi.export('bucket_url',\n    bucket.bucket.apply(lambda name: f'https://{name}.s3.amazonaws.com')\n)"}],"quickstart":{"code":"# 1. Install CLI: curl -fsSL https://get.pulumi.com | sh\n# 2. pip install pulumi pulumi-aws\n# 3. pulumi new aws-python\n# 4. Edit __main__.py:\n\nimport pulumi\nimport pulumi_aws as aws\n\n# Create an S3 bucket\nbucket = aws.s3.Bucket(\n    'my-bucket',\n    acl='private',\n    tags={'Environment': 'dev'}\n)\n\n# Create an EC2 security group\nsg = aws.ec2.SecurityGroup(\n    'web-sg',\n    description='Allow HTTP',\n    ingress=[aws.ec2.SecurityGroupIngressArgs(\n        protocol='tcp',\n        from_port=80,\n        to_port=80,\n        cidr_blocks=['0.0.0.0/0']\n    )]\n)\n\n# Stack exports — must be at top level\npulumi.export('bucket_name', bucket.bucket)\npulumi.export('bucket_arn', bucket.arn)\npulumi.export('sg_id', sg.id)\n\n# 5. pulumi up","lang":"python","description":"Pulumi Python — S3 bucket and security group with stack exports."},"warnings":[{"fix":"Install CLI: curl -fsSL https://get.pulumi.com | sh. Then: pulumi new <template> && pulumi up.","message":"'pip install pulumi' installs the SDK but does NOT install the CLI. Running Python files directly does nothing. Must install Pulumi CLI separately and run via 'pulumi up'.","severity":"breaking","affected_versions":"all"},{"fix":"Use .apply(lambda val: ...) to access the inner value. Or use Output.all() to combine multiple outputs.","message":"All resource properties (bucket.bucket, instance.id, etc.) return Output[T] — not plain values. Printing them shows '<pulumi.output.Output object>'. Cannot concatenate or format directly.","severity":"breaking","affected_versions":"all"},{"fix":"Call pulumi.export('key', output) at the top level — not inside apply(), functions, or conditionals.","message":"pulumi.export() called inside .apply() callbacks or functions is silently ignored. Stack outputs must be registered at the top level of __main__.py.","severity":"breaking","affected_versions":"all"},{"fix":"Keep pulumi CLI and pip install pulumi at the same major.minor version. Check: pulumi version && pip show pulumi.","message":"CLI version and SDK version should be kept in sync. Using CLI v3.114+ with SDK < v3.114 breaks --continue-on-error and other features added in that release.","severity":"gotcha","affected_versions":"all"},{"fix":"pip install pulumi pulumi-aws for AWS. pip install pulumi pulumi-azure-native for Azure.","message":"Provider packages (pulumi-aws, pulumi-azure-native, pulumi-gcp) must be installed separately. 'pip install pulumi' alone gives you no cloud resources.","severity":"gotcha","affected_versions":"all"},{"fix":"Don't use hasattr() on Pulumi resources. Check the resource type's documented properties instead.","message":"hasattr() does not work on Pulumi resource objects. Python output lifting overrides __getattr__ — hasattr will always return True for resource outputs even for non-existent properties.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use the Pulumi CLI: pulumi up, pulumi preview, pulumi destroy.","message":"Pulumi programs must be run via 'pulumi up' or 'pulumi preview' — not 'python __main__.py'. Running directly produces no output and doesn't register resources.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T09:44:37.486Z","next_check":"2026-06-25T00:00:00.000Z","problems":[{"fix":"Install the Pulumi CLI by following the instructions on the official Pulumi website (e.g., using `curl -fsSL https://get.pulumi.com | sh` for Linux/macOS or a direct download for Windows) and ensure its bin directory is added to your system's PATH.","cause":"The Pulumi CLI is either not installed on your system or its installation directory is not included in your system's PATH environment variable.","error":"pulumi: command not found"},{"fix":"Use the `.apply()` method of the `Output` to work with its resolved value. For JSON serialization, you might pass the `Output` to a function within `.apply()` that performs the serialization once the value is known. Alternatively, use `pulumi.Output.all()` for multiple outputs.","cause":"Pulumi resource properties return `Output[T]` objects, not direct primitive values, because their actual values might not be known until runtime during the deployment. Attempting to serialize an `Output` object directly (e.g., for logging or passing to a non-Pulumi function expecting a plain string or int) results in this error.","error":"TypeError: Object of type Output is not JSON serializable"},{"fix":"Activate your project's virtual environment and run `pip install pulumi` along with any necessary provider packages (e.g., `pip install pulumi_aws`, `pip install pulumi_azure_native`). Ensure your `Pulumi.yaml` is configured to use your virtual environment if applicable.","cause":"The Pulumi Python SDK or a required provider package (e.g., `pulumi_aws`) is not installed in the Python environment (virtual or global) that Pulumi is using to execute your program.","error":"ModuleNotFoundError: No module named 'pulumi'"},{"fix":"Refactor your code to ensure all `pulumi.export()` calls are made directly within your main Pulumi program file, after all resources have been defined. If exporting values from a `ComponentResource`, return them via `self.register_outputs()` from the component, and then export those outputs from the top-level program.","cause":"The `pulumi.export()` function must be called at the top level of your Pulumi program, outside of any functions or class constructors (especially `ComponentResource` constructors), as it registers stack outputs with the Pulumi engine.","error":"Failed to export output. Root resource is not an instance of 'Stack'"},{"fix":"Ensure that your Pulumi CLI and Pulumi SDK (and provider SDKs) are kept in sync, ideally using the latest stable versions for both. Upgrade both the CLI and your Python SDK dependencies to their latest compatible versions.","cause":"This obscure error often indicates a significant mismatch between the installed Pulumi CLI version and the Pulumi Python SDK version, possibly due to underlying protobuf library incompatibilities.","error":"Value out of range: 8589934588"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.28,"mem_mb":23.2,"disk_size":"85.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.57,"mem_mb":18.3,"disk_size":"71M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.92,"mem_mb":25.1,"disk_size":"91.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.01,"mem_mb":20.3,"disk_size":"77M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.94,"mem_mb":25,"disk_size":"82.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.26,"mem_mb":20.3,"disk_size":"71M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.8,"mem_mb":26.2,"disk_size":"81.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.2,"mem_mb":21.3,"disk_size":"71M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.97,"mem_mb":19.8,"disk_size":"75.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.51,"mem_mb":15.1,"disk_size":"61M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}