Skip to main content

pycfmodel

Build Status PyPI version Documentation Status License

A python model for Cloud Formation scripts.

pycfmodel makes it easier to work with CloudFormation scripts in Python by creating a model comprised of python objects. Objects have various helper functions which help with performing common tasks related to parsing and inspecting CloudFormation scripts.

pip install pycfmodel

Currently Supported

  • AWSTemplateFormatVersion
  • Conditions
  • Description
  • Mappings
  • Metadata
  • Outputs
  • Parameters
  • Resources:
    • Properties:
      • Policy
      • Policy Document
      • Principal
      • Security Group Egress Prop
      • Security Group Ingress Prop
      • Statement
      • Tag
    • EC2 VPC Endpoint Policy
    • Generic Resource
    • IAM Group
    • IAM Managed Policy
    • IAM Policy
    • IAM Role
    • IAM User
    • KMS Key
    • OpenSearch Service (legacy ElasticSearch resource)
      • Elasticsearch Domain
    • OpenSearch Service
      • OpenSearchService Domain
    • S3 Bucket
    • S3 Bucket Policy
    • Security Group
    • Security Group Egress
    • Security Group Ingress
    • SNS Topic Policy
    • SQS Queue Policy
    • WAFv2 IP Set
  • Transform

Example

from pycfmodel import parse

template = {
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {"StarParameter": {"Type": "String", "Default": "*", "Description": "Star Param"}},
    "Resources": {
        "rootRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Effect": "Allow",
                            "Principal": {"AWS": {"Fn::Sub": "arn:aws:iam::${AWS::AccountId}:root"}},
                            "Action": ["sts:AssumeRole"],
                        }
                    ],
                },
                "Path": "/",
                "Policies": [
                    {
                        "PolicyName": "root",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Effect": "Allow",
                                    "Action": {"Ref": "StarParameter"},
                                    "Resource": {"Ref": "StarParameter"},
                                }
                            ],
                        },
                    }
                ],
            },
        }
    },
}

model = parse(template).resolve(extra_params={"AWS::AccountId": "123"})
rootRole = model.Resources["rootRole"]
policy = rootRole.Properties.Policies[0]
statement = policy.PolicyDocument.Statement[0]

assert statement.Action == "*"
assert statement.Resource == "*"
assert rootRole.Properties.AssumeRolePolicyDocument.Statement[0].Principal == {"AWS": "arn:aws:iam::123:root"}

Local Development Commands

This project uses uv for dependency management.

make install-dev    # Install all development dependencies
make coverage       # Run tests with coverage
make test           # Run linting and tests
make lock           # Update uv.lock file
make lock-upgrade   # Upgrade all dependencies and update uv.lock

Updating CloudFormation Actions

If the test tests/test_constants.py::test_cloudformation_actions is failing, it can be resolved by updating the known AWS Actions:

make install-cloudformation-update
make cloudformation-update

Metadata

Release files for pycfmodel 2.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycfmodel 2.1.4
File Size Uploaded Provenance Actions
pycfmodel-2.1.4.tar.gz 313.2 kB Without provenance Details for pycfmodel-2.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycfmodel 2.1.4
File Interpreter ABI Platform Actions
pycfmodel-2.1.4-py3-none-any.whl Python 3 none any Details for pycfmodel-2.1.4-py3-none-any.whl

Total release size: 510.7 kB

Release files / pycfmodel-2.1.4.tar.gz

Download URL pycfmodel-2.1.4.tar.gz
Size 313.2 kB
Tags Source
SHA-256 checksum
How to use checksums
61f345dd203a6f0dd4d29fa18a815d17e6639ac93d3196072ca1c1d7f7647225
BLAKE2b-256 checksum
How to use checksums
84a28fc7de33379cbb443ed4efe3f8f2178397a3bf4528d0c4d8e5c5654a91a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pycfmodel-2.1.4-py3-none-any.whl

Download URL pycfmodel-2.1.4-py3-none-any.whl
Size 197.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbe8232d89bd8aa0b68be6087e3ca3b93c554b82ec002b74036f5d41380d7367
BLAKE2b-256 checksum
How to use checksums
9f20d7be9ee255a76d98afe1fcc0e105c7b4148bfa29ab6d90011c4745e80284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for pycfmodel 2.1.4

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.

Release history Release notifications | RSS feed

This release

2.1.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page