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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycfmodel-2.1.2.tar.gz (306.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycfmodel-2.1.2-py3-none-any.whl (194.0 kB view details)

Uploaded Python 3

File details

Details for the file pycfmodel-2.1.2.tar.gz.

File metadata

  • Download URL: pycfmodel-2.1.2.tar.gz
  • Upload date:
  • Size: 306.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pycfmodel-2.1.2.tar.gz
Algorithm Hash digest
SHA256 437b535efea69eae77be59b369ebad19214afd808bf1ddf95387456096dcd019
MD5 4cb8934041fbbb781b835c18c9a134d1
BLAKE2b-256 0adb58f46626c8c33da9115dd3263e6cbea7edc66806671203d610bb6827ff09

See more details on using hashes here.

File details

Details for the file pycfmodel-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: pycfmodel-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 194.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pycfmodel-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2455e7ddb6c0b97178d0051630fd014733468e7250ba19cbafc65ca42d7c45d
MD5 4c0a526260e68dcf50578bf5e8c52995
BLAKE2b-256 54764087eb491ed966b5b42da9c8bcde27419ebb6ccb5e3fcc6c190a9a9192b2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 files

2.1.1

2 files

2.1.0

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.22.0

2 files

0.21.2

2 files

0.21.1

2 files

0.21.0

2 files

0.20.3

2 files

0.20.2

2 files

0.20.1

2 files

0.20.0

2 files

0.19.1

2 files

0.19.0

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.3

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.4

2 files

0.10.3

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

1 file

0.7.1

1 file

0.7.0

1 file

0.6.4

1 file

0.6.3

1 file

0.6.1

1 file

0.6.0

1 file

0.5.1

1 file

0.5.0

1 file

0.4.0

1 file

0.3.2

1 file

0.2.12

1 file

0.2.11

1 file

0.2.10

1 file

0.2.9

1 file

0.2.8

1 file

0.2.7

1 file

0.2.6

1 file

0.2.5

1 file

0.2.4

1 file

0.2.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page