cfn-flip


Namecfn-flip JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/awslabs/aws-cfn-template-flip
SummaryConvert AWS CloudFormation templates between JSON and YAML formats
upload_time2021-10-07 10:05:14
maintainer
docs_urlNone
authorSteve Engledow
requires_python
licenseApache2
keywords
VCS
bugtrack_url
requirements Click PyYAML six tox
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build Status](https://www.travis-ci.org/awslabs/aws-cfn-template-flip.svg?branch=master)](https://www.travis-ci.org/awslabs/aws-cfn-template-flip)
[![PyPI version](https://badge.fury.io/py/cfn-flip.svg)](https://badge.fury.io/py/cfn-flip)
[![Codecov Test Coverage](https://codecov.io/gh/awslabs/aws-cfn-template-flip/branch/master/graphs/badge.svg?style=flat)](https://codecov.io/gh/awslabs/aws-cfn-template-flip)
[![Snap Status](https://build.snapcraft.io/badge/awslabs/aws-cfn-template-flip.svg)](https://build.snapcraft.io/user/awslabs/aws-cfn-template-flip)

[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/cfn-flip)

# AWS CloudFormation Template Flip

## About

AWS CloudFormation Template Flip is a tool that converts [AWS CloudFormation](https://aws.amazon.com/cloudformation/) templates between [JSON](http://json.org/) and [YAML](http://yaml.org) formats, making use of the YAML format's short function syntax where possible.

The term "Flip" is inspired by the well-known Unix command-line tool [flip](https://ccrma.stanford.edu/~craig/utility/flip/) which converts text files between Unix, Mac, and MS-DOS formats.

## Installation

AWS CloudFormation Template Flip can be installed using [pip](https://pip.pypa.io/en/stable/):

```bash
pip install cfn-flip
```

## Usage

AWS CloudFormation Template Flip is both a command line tool and a python library.

Note that the command line tool is spelled `cfn-flip` with a hyphen, while the python package is `cfn_flip` with an underscore.

### Command line tool

```
Usage: cfn-flip [OPTIONS] [INPUT] [OUTPUT]

  AWS CloudFormation Template Flip is a tool that converts AWS
  CloudFormation templates between JSON and YAML formats, making use of the
  YAML format's short function syntax where possible."

Options:
  -i, --input [json|yaml]   Specify the input format. Overrides -j and -y
                            flags.
  -o, --output [json|yaml]  Specify the output format. Overrides -j, -y, and
                            -n flags.
  -j, --json                Convert to JSON. Assume the input is YAML.
  -y, --yaml                Convert to YAML. Assume the input is JSON.
  -c, --clean               Performs some opinionated cleanup on your
                            template.
  -l, --long                Use long-form syntax for functions when converting
                            to YAML.
  -n, --no-flip             Perform other operations but do not flip the
                            output format.
  --version                 Show the version and exit.
  --help                    Show this message and exit.
```


cfn-flip will detect the format of the input template and convert JSON to YAML and YAML to JSON, respectively.

Examples:

* Reading from `stdin` and outputting to `stdout`:

    ```bash
    cat examples/test.json | cfn-flip
    ```

* Reading from a file and outputting to `stdout`:

    ```bash
    cfn-flip examples/test.yaml
    ```

* Reading from a file and outputting to another file:

    ```bash
    cfn-flip examples/test.json output.yaml
    ```

* Reading from a file and cleaning up the output

    ```bash
    cfn-flip -c examples/test.json
    ```

### Python package

To use AWS CloudFormation Template Flip from your own python projects, import one of the functions `flip`, `to_yaml`, or `to_json` as needed.

```python
from cfn_flip import flip, to_yaml, to_json

"""
All functions expect a string containing serialised data
and return a string containing serialised data
or raise an exception if there is a problem parsing the input
"""

# flip takes a best guess at the serialisation format
# and returns the opposite, converting json into yaml and vice versa
some_yaml_or_json = flip(some_json_or_yaml)

# to_json expects serialised yaml as input, and returns serialised json
some_json = to_json(some_yaml)

# to_yaml expects serialised json as input, and returns serialised yaml
some_yaml = to_yaml(some_json)

# The clean_up flag performs some opinionated, CloudFormation-specific sanitation of the input
# For example, converting uses of Fn::Join to Fn::Sub
# flip, to_yaml, and to_json all support the clean_up flag
clean_yaml = to_yaml(some_json, clean_up=True)
```

### Configuration paramters

You can configure some parameters like:

`max_col_width`: Maximum columns before breakline. Default value is 200
To change the configuration you can use:

**Environment Variable**

Linux/Unix:
`export CFN_MAX_COL_WIDTH=120`

Windows: `SET CFN_MAX_COL_WIDTH=120`

**Python**

```python

from cfn_tools._config import config
from cfn_flip import flip, to_yaml, to_json

"""
All functions expect a string containing serialised data
and return a string containing serialised data
or raise an exception if there is a problem parsing the input
"""

# Change the default number of columns to break line to 120
config['max_col_width'] = "120"

# flip takes a best guess at the serialisation format
# and returns the opposite, converting json into yaml and vice versa
some_yaml_or_json = flip(some_json_or_yaml)

# to_json expects serialised yaml as input, and returns serialised json
some_json = to_json(some_yaml)

# to_yaml expects serialised json as input, and returns serialised yaml
some_yaml = to_yaml(some_json)

# The clean_up flag performs some opinionated, CloudFormation-specific sanitation of the input
# For example, converting uses of Fn::Join to Fn::Sub
# flip, to_yaml, and to_json all support the clean_up flag
clean_yaml = to_yaml(some_json, clean_up=True)

```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/awslabs/aws-cfn-template-flip",
    "name": "cfn-flip",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Steve Engledow",
    "author_email": "sengledo@amazon.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/ca/75/8eba0bb52a6c58e347bc4c839b249d9f42380de93ed12a14eba4355387b4/cfn_flip-1.3.0.tar.gz",
    "platform": "",
    "description": "[![Build Status](https://www.travis-ci.org/awslabs/aws-cfn-template-flip.svg?branch=master)](https://www.travis-ci.org/awslabs/aws-cfn-template-flip)\n[![PyPI version](https://badge.fury.io/py/cfn-flip.svg)](https://badge.fury.io/py/cfn-flip)\n[![Codecov Test Coverage](https://codecov.io/gh/awslabs/aws-cfn-template-flip/branch/master/graphs/badge.svg?style=flat)](https://codecov.io/gh/awslabs/aws-cfn-template-flip)\n[![Snap Status](https://build.snapcraft.io/badge/awslabs/aws-cfn-template-flip.svg)](https://build.snapcraft.io/user/awslabs/aws-cfn-template-flip)\n\n[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/cfn-flip)\n\n# AWS CloudFormation Template Flip\n\n## About\n\nAWS CloudFormation Template Flip is a tool that converts [AWS CloudFormation](https://aws.amazon.com/cloudformation/) templates between [JSON](http://json.org/) and [YAML](http://yaml.org) formats, making use of the YAML format's short function syntax where possible.\n\nThe term \"Flip\" is inspired by the well-known Unix command-line tool [flip](https://ccrma.stanford.edu/~craig/utility/flip/) which converts text files between Unix, Mac, and MS-DOS formats.\n\n## Installation\n\nAWS CloudFormation Template Flip can be installed using [pip](https://pip.pypa.io/en/stable/):\n\n```bash\npip install cfn-flip\n```\n\n## Usage\n\nAWS CloudFormation Template Flip is both a command line tool and a python library.\n\nNote that the command line tool is spelled `cfn-flip` with a hyphen, while the python package is `cfn_flip` with an underscore.\n\n### Command line tool\n\n```\nUsage: cfn-flip [OPTIONS] [INPUT] [OUTPUT]\n\n  AWS CloudFormation Template Flip is a tool that converts AWS\n  CloudFormation templates between JSON and YAML formats, making use of the\n  YAML format's short function syntax where possible.\"\n\nOptions:\n  -i, --input [json|yaml]   Specify the input format. Overrides -j and -y\n                            flags.\n  -o, --output [json|yaml]  Specify the output format. Overrides -j, -y, and\n                            -n flags.\n  -j, --json                Convert to JSON. Assume the input is YAML.\n  -y, --yaml                Convert to YAML. Assume the input is JSON.\n  -c, --clean               Performs some opinionated cleanup on your\n                            template.\n  -l, --long                Use long-form syntax for functions when converting\n                            to YAML.\n  -n, --no-flip             Perform other operations but do not flip the\n                            output format.\n  --version                 Show the version and exit.\n  --help                    Show this message and exit.\n```\n\n\ncfn-flip will detect the format of the input template and convert JSON to YAML and YAML to JSON, respectively.\n\nExamples:\n\n* Reading from `stdin` and outputting to `stdout`:\n\n    ```bash\n    cat examples/test.json | cfn-flip\n    ```\n\n* Reading from a file and outputting to `stdout`:\n\n    ```bash\n    cfn-flip examples/test.yaml\n    ```\n\n* Reading from a file and outputting to another file:\n\n    ```bash\n    cfn-flip examples/test.json output.yaml\n    ```\n\n* Reading from a file and cleaning up the output\n\n    ```bash\n    cfn-flip -c examples/test.json\n    ```\n\n### Python package\n\nTo use AWS CloudFormation Template Flip from your own python projects, import one of the functions `flip`, `to_yaml`, or `to_json` as needed.\n\n```python\nfrom cfn_flip import flip, to_yaml, to_json\n\n\"\"\"\nAll functions expect a string containing serialised data\nand return a string containing serialised data\nor raise an exception if there is a problem parsing the input\n\"\"\"\n\n# flip takes a best guess at the serialisation format\n# and returns the opposite, converting json into yaml and vice versa\nsome_yaml_or_json = flip(some_json_or_yaml)\n\n# to_json expects serialised yaml as input, and returns serialised json\nsome_json = to_json(some_yaml)\n\n# to_yaml expects serialised json as input, and returns serialised yaml\nsome_yaml = to_yaml(some_json)\n\n# The clean_up flag performs some opinionated, CloudFormation-specific sanitation of the input\n# For example, converting uses of Fn::Join to Fn::Sub\n# flip, to_yaml, and to_json all support the clean_up flag\nclean_yaml = to_yaml(some_json, clean_up=True)\n```\n\n### Configuration paramters\n\nYou can configure some parameters like:\n\n`max_col_width`: Maximum columns before breakline. Default value is 200\nTo change the configuration you can use:\n\n**Environment Variable**\n\nLinux/Unix:\n`export CFN_MAX_COL_WIDTH=120`\n\nWindows: `SET CFN_MAX_COL_WIDTH=120`\n\n**Python**\n\n```python\n\nfrom cfn_tools._config import config\nfrom cfn_flip import flip, to_yaml, to_json\n\n\"\"\"\nAll functions expect a string containing serialised data\nand return a string containing serialised data\nor raise an exception if there is a problem parsing the input\n\"\"\"\n\n# Change the default number of columns to break line to 120\nconfig['max_col_width'] = \"120\"\n\n# flip takes a best guess at the serialisation format\n# and returns the opposite, converting json into yaml and vice versa\nsome_yaml_or_json = flip(some_json_or_yaml)\n\n# to_json expects serialised yaml as input, and returns serialised json\nsome_json = to_json(some_yaml)\n\n# to_yaml expects serialised json as input, and returns serialised yaml\nsome_yaml = to_yaml(some_json)\n\n# The clean_up flag performs some opinionated, CloudFormation-specific sanitation of the input\n# For example, converting uses of Fn::Join to Fn::Sub\n# flip, to_yaml, and to_json all support the clean_up flag\nclean_yaml = to_yaml(some_json, clean_up=True)\n\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache2",
    "summary": "Convert AWS CloudFormation templates between JSON and YAML formats",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/awslabs/aws-cfn-template-flip"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ba8a67297cd63ef99c3391c1d143161b187b71afa715a988655758269e3d02f",
                "md5": "d6d014cee8385bcd4bf978db59b9f6f9",
                "sha256": "faca8e77f0d32fb84cce1db1ef4c18b14a325d31125dae73c13bcc01947d2722"
            },
            "downloads": -1,
            "filename": "cfn_flip-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d6d014cee8385bcd4bf978db59b9f6f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21387,
            "upload_time": "2021-10-07T10:05:13",
            "upload_time_iso_8601": "2021-10-07T10:05:13.378812Z",
            "url": "https://files.pythonhosted.org/packages/2b/a8/a67297cd63ef99c3391c1d143161b187b71afa715a988655758269e3d02f/cfn_flip-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ca758eba0bb52a6c58e347bc4c839b249d9f42380de93ed12a14eba4355387b4",
                "md5": "d01c5f2f76cde0b98073ab81c6517be5",
                "sha256": "003e02a089c35e1230ffd0e1bcfbbc4b12cc7d2deb2fcc6c4228ac9819307362"
            },
            "downloads": -1,
            "filename": "cfn_flip-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d01c5f2f76cde0b98073ab81c6517be5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16113,
            "upload_time": "2021-10-07T10:05:14",
            "upload_time_iso_8601": "2021-10-07T10:05:14.956894Z",
            "url": "https://files.pythonhosted.org/packages/ca/75/8eba0bb52a6c58e347bc4c839b249d9f42380de93ed12a14eba4355387b4/cfn_flip-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-10-07 10:05:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "awslabs",
    "github_project": "aws-cfn-template-flip",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "Click",
            "specs": []
        },
        {
            "name": "PyYAML",
            "specs": []
        },
        {
            "name": "six",
            "specs": []
        },
        {
            "name": "tox",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "cfn-flip"
}
        
Elapsed time: 0.56229s