IAM Policy Builder
Build valid IAM policies for Google Cloud (GCP) and Amazon Web Services (AWS)
Features
Fluent chaining for clean code
Output standard JSON-compatible dictionaries
Avoid error-prone string manipulation
Installation
You can install this package via PIP: pip install python-iam-policy-builder
Usage
GCP
from iam_policy.gcp.gcp_iam_policy_builder import GCPIAMPolicyBuilder, Condition
iam_policy = GCPIAMPolicyBuilder(version=3)
iam_policy.add_binding(
role='roles/viewer',
members=[
'user:alice@example.com',
'serviceAccount:compute@example.com'
],
condition=Condition(
title='TimeBoundAccess',
expression='request.time < timestamp("2024-12-31T23:59:59Z")',
description='Temporary access until end of year'
)._asdict()
)
print(iam_policy.build())
# [Output]
# {
# "bindings": [
# {
# "role": "roles/viewer",
# "members": [
# "user:alice@example.com",
# "serviceAccount:compute@example.com"
# ],
# "condition": {
# "title": "TimeBoundAccess",
# "expression": "request.time < timestamp(\"2024-12-31T23:59:59Z\")",
# "description": "Temporary access until end of year"
# }
# }
# ],
# "version": 3
# }
AWS
from iam_policy.aws.aws_iam_policy_builder import AWSIAMPolicyBuilder, Statement, Effect
iam_policy = AWSIAMPolicyBuilder(version='2012-10-17')
iam_policy.add_statement(
Statement(
Effect=Effect.Allow.value,
Action=['iam:ListUsers'],
Resource=['arn:aws:s3:::my-bucket/*'],
Sid='AllowListUsers',
Condition={
'StringEquals': {
'aws:username': 'alice'
}
},
Principal={'AWS': 'arn:aws:iam::123456789012:user/alice'},
)._asdict()
)
print(iam_policy.build())
# [Output]
# {
# "Version": "2012-10-17",
# "Statement": [
# {
# "Effect": "Allow",
# "Action": [
# "iam:ListUsers"
# ],
# "Resource": [
# "arn:aws:s3:::my-bucket/*"
# ],
# "Condition": {
# "StringEquals": {
# "aws:username": "alice"
# }
# },
# "Sid": "AllowListUsers",
# "Principal": {'AWS': 'arn:aws:iam::123456789012:user/alice'}
# }
# ]
# }
Notes
GCP
- Multiple conditions per binding are not supported, as GCP IAM currently allows only one condition per binding (as of May 2025)
- auditConfigs (Used for configuring audit logging) are not supported
- Role names, member identifiers, and condition expressions are not validated
AWS
- No validation is performed on ARNs, actions, or conditions
Metadata
Release files for python-iam-policy-builder 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_iam_policy_builder-0.1.6.tar.gz | 5.8 kB | Without provenance | Details for python_iam_policy_builder-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_iam_policy_builder-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for python_iam_policy_builder-0.1.6-py3-none-any.whl |
Total release size: 12.6 kB
Release files / python_iam_policy_builder-0.1.6.tar.gz
| Download URL | python_iam_policy_builder-0.1.6.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bedd0ba9b3bd8a434c93353642a9fb0d0ee243881cb9fadd579d63f5f1f1bf21
|
|
BLAKE2b-256 checksum How to use checksums |
b7caa4cec9cf55e669ec28ef5a4458ff5469c36823ed1d2bc6f6f849ef64f335
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / python_iam_policy_builder-0.1.6-py3-none-any.whl
| Download URL | python_iam_policy_builder-0.1.6-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87f00ef9a5abe11d4bc400d6e7c0fa896d64acc8a11f355b991b22a3a853a593
|
|
BLAKE2b-256 checksum How to use checksums |
535fe22547ce13b84a1b22d79bacc0be2a055340a078a95a58e958af62dea6c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Security for python-iam-policy-builder 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.