cottonformation is a Python tool providing best development experience and highest productivity

Overview
https://readthedocs.org/projects/cottonformation/badge/ https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social

Welcome to cottonformation Documentation

Full Documentatioin Here

cottonformation is a Python tool providing best development experience and highest productivity. Powered by modern Type Hint, Advanced Auto Complete, Parameter Hint, Instant official AWS Document look up. Here's how it looks like in PyCharm (Supported by PyCharm out-of-the-box, but you can configure it by installing extension or plugin in VSCode, Sublime, Atom ...).

Note

This example is based on PyCharm + MacOS. The shortcut key could be different on different OS (Windows / Linux) / IDE (VSCode / Sublime / Atom ...).

  1. Type hint and property hint: tell you what property is available, what is the type, and auto complete the code for you. rp prefix stands for Required Property, p prefix stands for Optional Property, you can navigate property using UP and DOWN key. You can also view available property and type (Cmd + P), see how at View Parameter Info.

https://user-images.githubusercontent.com/6800411/123467578-a691af00-d5be-11eb-8869-83c0db3253b5.gif

  1. Return value hint: tell you what return value is available, and allow you instantly acccess it without need looking up the AWS Document. You don't need to remember ANY API. To be honest, looking up the exact Resource Attribute Name in https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html and then GetAtt(resource_object, attribute_name) is really UGLY!

https://user-images.githubusercontent.com/6800411/123468458-ca092980-d5bf-11eb-906b-793c148dc3c0.gif

  1. Parameter hint: tell you all available parameter and its type (Cmd + P). It works on both Resource Type and complex Property Type.

https://user-images.githubusercontent.com/6800411/123477456-19eded80-d5cc-11eb-84a6-7c864e39a142.gif

  1. Jump to resource doc: instantly open the AWS Doc about this AWS Resource in web browser. Click on the class, hit F1 and click on the link.

https://user-images.githubusercontent.com/6800411/123477362-f0cd5d00-d5cb-11eb-9d09-32cfb1d96710.gif

  1. Jump to property doc method 1: instantly open the AWS Doc about this Resource Property in web browser. Click on the class, hit F1 (view doc string), find the property and click on the link.

https://user-images.githubusercontent.com/6800411/123478114-ff684400-d5cc-11eb-8a62-f168d3ae4ed3.gif

  1. Jump to property doc method 2: reference the resource property using resource_object.property_name syntax, click on the property, hit F1 (view doc string), and click on the link.

https://user-images.githubusercontent.com/6800411/123478125-042cf800-d5cd-11eb-8fc9-80cb5507845b.gif

  1. Jump to return value doc: reference the resource attribute using resource_object.attribute_name syntax, click on the property, hit F1 (view doc string), and click on the link.

https://user-images.githubusercontent.com/6800411/123478144-0bec9c80-d5cd-11eb-8260-a9de04690177.gif

A sample infrastructure as code script may looks like this. And you can immediately deploy it from Python:

# -*- coding: utf-8 -*-

# First, import cottonformation, I prefer to use ctf for a short name
import cottonformation as ctf

# import the aws service module you need
from cottonformation.res import iam, awslambda

# create a ``Template`` object to represent your cloudformation template
tpl = ctf.Template()

# create a ``Parameter`` object, and add it to template.
param_env_name = ctf.Parameter(
    "EnvName",
    Type=ctf.Parameter.TypeEnum.String,
)
tpl.add(param_env_name)

# create a ``Resource`` object for aws iam role
iam_role_for_lambda = iam.Role(
    "IamRoleForLambdaExecution",
    # you don't need to remember the exact name or syntax for
    # trusted entity / assume role policy, cottonformation has a helper for this
    rp_AssumeRolePolicyDocument=ctf.helpers.iam.AssumeRolePolicyBuilder(
        ctf.helpers.iam.ServicePrincipal.awslambda()
    ).build(),
    p_RoleName=ctf.Sub("${EnvName}-iam-role-for-lambda", dict(EnvName=param_env_name.ref())),
    p_Description="Minimal iam role for lambda execution",
    # you don't need to remember the exact ARN for aws managed policy.
    # cottonformation has a helper for this
    p_ManagedPolicyArns=[
        ctf.helpers.iam.AwsManagedPolicy.AWSLambdaBasicExecutionRole,
    ]
)
tpl.add(iam_role_for_lambda)


# create a ``Resource`` object for aws lambda function
lbd_source_code = """
def handler(event, context):
    return "hello cottonformation"
""".strip()

lbd_func = awslambda.Function(
    "LbdFuncHelloWorld",
    # rp_ stands for Required Property, it will gives you parameter-hint
    # for all valid required properties.
    rp_Code=awslambda.FunctionCode(
        p_ZipFile=lbd_source_code,
    ),
    # normally we need to explicitly call GetAtt(resource, attribute)
    # and you need to remember the exact attribute name
    # but cottonformation allow you to instantly reference the attribute
    # powered by auto-complete. the prefix rv_ stands for Return Value
    rp_Role=iam_role_for_lambda.rv_Arn,
    # p_ stands for Property, it will gives you parameter-hint
    # for all valid properties
    p_MemorySize=256,
    p_Timeout=3,
    # some constant value helper here too
    p_Runtime=ctf.helpers.awslambda.LambdaRuntime.python37,
    p_Handler="index.handler",
    ra_DependsOn=iam_role_for_lambda,
)
tpl.add(lbd_func)

out_lambda_role_arn = ctf.Output(
    "LbdRoleArn",
    Description="aws lambda basic execution iam role for reuse",
    Value=iam_role_for_lambda.rv_Arn
)
tpl.add(out_lambda_role_arn)


if __name__ == "__main__":
    # my private aws account session and bucket for testing
    from cottonformation.tests.boto_ses import boto_ses, bucket

    # define the Parameter.EnvName value
    env_name = "ctf-1-quick-start-1-basic"

    # create an environment for deployment, it is generally a boto3 session
    # and a s3 bucket to upload cloudformation template
    env = ctf.Env(boto_ses=boto_ses)
    env.deploy(
        template=tpl,
        stack_name=env_name,
        stack_parameters=dict(
            EnvName=env_name,
        ),
        bucket_name=bucket,
        include_iam=True,
    )

Getting Help

  1. The easiest way to learn the best practice is to learn by example. You can start from cottonformation by example. Then you can learn best practice proved in production environment in cottonformation best practice.
  2. Second method is to submit an GitHub issue. So other people may see the discussion and solution too. In addition there's a cottonformation community on gitter to directly ASK THE AUTHOR.

Overview

Why this Project?

The Goal:

There are lots of Cloud infrastructure as code tools available AWS CloudFormation, Terraform, troposphere, aws cdk, pulumi. They all be good in different way. cottonformation is not trying to beat or replace any of them, but focus on being the best in it's special way.

  1. Most productive for development.
  2. Most user friendly, no memorization, no difficult learning curve.
  3. Less code, light weight, easy to customize and extend.

The History:

The first generation Infrastructure as Code (IAC) might be AWS CloudFormation firstly released on 2011 and Terraform firstly released on 2014. The first generation IAC are mostly Domain specific language (DSL). They are not as powerful as general programming language like Java, C#, Python, Ruby, Go. Because of the nature DSL, it is hard to manipulate data, customize logic flow, poor code reusability, difficult to customize and extend.

The rule breaker troposphere was released on 2013. It is a Python project allow you to write CloudFormation template in Python using Objective Oriented programming model. But due to the initial code design, natively it is not able to support modern developer features like "Auto Complete" and "Type Hint". As a result, at least 50% of development time is used in lookup manual, read documentations. At mean time, AWS Cloudformation is evolving very fast supporting more AWS Resource. Since troposphere relies on maintainer adding implementation manually, it usually falls behind the latest feature.

I started to maintain a parallel library troposphere_mate to support "Auto Complete" and "Type Hint" and more advanced feature. However, it cannot evolve fast since it is based on troposphere and I have no control at all on it. I used to think of re-design a new project using latest programming model to replace troposphere in my Organization. But there are 162 AWS Service, 768 AWS Resource, 2,499 AWS Property and 43,200 lines of declaration code to work on. It is impossible to keep it up-to-date as an individual developer.

Fortunately, AWS published the AWS CloudFormation resource specification as a machine readable json file, and type hint and static check technology is already mature in Python community, I believe it is a good timing to re-invent a modernized CloudFormation tool. I figured out a way to automatically generate the 162 AWS Service, 768 AWS Resource, 2,499 AWS Property and 43,200 lines of declaration code with type hint / auto complete / aws doc jump features. Now we can easily keep cottonformation up-to-date with AWS CloudFormation!

What about AWS CDK or Pulumi?

Again, cottomformation don't want to be the improved AWS CDK or Pulumi. It want to do the best on the limited, but important feature as IAC tool.

AWS CDK:

Python is not first class member in AWS CDK. The nature of AWS CDK is a TypeScript Library, and AWS find a way to call TypeScript / JavaScript API from other programming language like Java / Ruby / Python / C# / Go. When you run AWS CDK in programming language other than TypeScript, the code is actually been converted to low level api, and been handled by the backend TypeScript code. This causes two issue:

  1. Significant delay in editing. Since "Type hint" and "Code Complete" is based on static code analysis technique and Python import engine. But internally AWS CDK import the underlying compiled Python - TypeScript *.jsii code when you import a AWS Resource declaration class. This is why it's slow with a 2019, 16GB memory Macbook Pro.
  2. Hard to customize and extend. Because the python code is underlying calling TypeScript API, there's no way you can inject your custom logic in the python code because it is not recognized by TypeScript API.
  3. You have to configure the Node.JS environment the Node.JS version of AWS CDK. In python community, we expect a simple pip install something then import something. You need additional configuration steps when you run it in a remote or a CI environment.

Pulumi:

Pulumi is more like terraform. Unlike troposphere and AWS CDK, it doesn't convert script to CloudFormation, but using it's own executing engine to deploy resources. Although it is easy to learn and worth, but you need to learn lots of new concept and component.

Install

cottonformation is released on PyPI, so all you need is:

$ pip install cottonformation

To upgrade to latest version:

$ pip install --upgrade cottonformation
You might also like...
A Python code editor that looks like GNU Emacs.
A Python code editor that looks like GNU Emacs.

🚧 WARNING 🚧 : Under development... Testing is not recommended! Welcome to Snake Editor! Hi! This is our repository, we are here to present our new p

This is code for IDLE python/ Magic8Ball Code

Magic8Ball this is code for IDLE python/ Magic8Ball Code this code is for beginers i hope you can learn code form this don't ever be a script kiddie a

Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser

Live Coding in Python Visualize your Python code while you type it in PyCharm, Emacs, Sublime Text, or even your browser. To see how to use one of the

An amazing simple Python IDE for developers!
An amazing simple Python IDE for developers!

PyHub An amazing simple Python IDE for developers! Get ready to compile and run your code in the most simplest and easiest IDE of the ancient world! T

Automatically detect obfuscated code and other state machines
Automatically detect obfuscated code and other state machines

Scripts to automatically detect obfuscated code and state machines in binaries.

💻 Open recent VS Code folders and files using Ulauncher

ulauncher-vscode-recent 💻 Open recent VS Code folders and files using Ulauncher. Quickly open recently-opened VS Code project directories and files.

A Sublime Text package that allows a user to view all the available core/plugin commands for Sublime Text and Sublime Merge, along with their documentation/source.
A Sublime Text package that allows a user to view all the available core/plugin commands for Sublime Text and Sublime Merge, along with their documentation/source.

CommandsBrowser A Sublime Text package that allows a user to view all the available core/plugin commands for Sublime Text and Sublime Merge, along wit

A way to integrate Latex, VSCode, and Inkscape in macOS. Adopted the whole workflow from Gilles Castel.
A way to integrate Latex, VSCode, and Inkscape in macOS. Adopted the whole workflow from Gilles Castel.

VSCode-LaTeX-Inkscape A way to integrate LaTeX, VSCode, and Inkscape in macOS Abstract I use LaTeX heavily in past two years for both academic work an

SC4.0 - BEST EXPERIENCE · HEX EDITOR · Discord Nuker · Plugin Adder · Cheat Engine

smilecreator4 This site is for people who want to hack or want to learn it! Furthermore, this program does not work without turning off Antivirus or W

The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.
The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

django-crispy-forms The best way to have Django DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered

The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.
The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

django-crispy-forms The best way to have Django DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered

The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.
The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

django-crispy-forms The best way to have Django DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered

Download Apple Music Cover Artwork in the best Quality by providing an Apple Music Link. It downloads the jpg, png and webp version since they often differ from another.
Download Apple Music Cover Artwork in the best Quality by providing an Apple Music Link. It downloads the jpg, png and webp version since they often differ from another.

amogus.py - Version 0.0.5 amogus - Apple Music Hi-Res Artwork Fetcher this is my first real python tool so sorry if its bad amogus is a Python script

Useful PDF-related productivity tool.
Useful PDF-related productivity tool.

Luftmensch 1.4.7 (Español) | 1.4.3 (English) Version 1.4.7 (Español) released in October 2021. Version 1.4.3 (English) released in September 2021. 🏮

Use this script to track the gains of cryptocurrencies using historical data and display it on a super-imposed chart in order to find the highest performing cryptocurrencies historically

crypto-performance-tracker Use this script to track the gains of cryptocurrencies using historical data and display it on a super-imposed chart in ord

AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks.
AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks.

AutoPilot AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks. C

Arras.io Highest Scores Over Time Bar Chart Race

Arras.io Highest Scores Over Time Bar Chart Race This repo contains a python script (make_racing_bar_chart.py) that can generate a csv file which can

Consecutive-Subsequence - Simple software to calculate susequence with highest sum

Simple software to calculate susequence with highest sum This repository contain

Comments
  • Condition support

    Condition support

    I searched around a bit and couldn't find an implementation of the Condition intrinsic functions. Does cottonformation have a solution for that currently?

    enhancement 
    opened by ipmb 3
  • Add a Gitter chat badge to README.rst

    Add a Gitter chat badge to README.rst

    MacHu-GWU/cottonformation-project now has a Chat Room on Gitter

    @MacHu-GWU has just created a chat room. You can visit it here: https://gitter.im/cottonformation/community.

    This pull-request adds this badge to your README.rst:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
  • [Don't Delete] Document Image Host

    [Don't Delete] Document Image Host

    This issue is for hosting demo image for document, don't touch!

    Type hint and property hint

    type-hint-and-param-hint

    Return value hint

    return-value-hint

    Parameter hint

    param-hint

    Jump to resource doc

    jump-to-resource-doc

    Jump to property doc 1

    jump-to-property-doc-1

    Jump to property doc 2

    jump-to-property-doc-2

    Jump to return value doc

    jump-to-return-value-doc

    wontfix 
    opened by MacHu-GWU 1
Releases(1.0.1)
Owner
Sanhe
Cloud Data Architect focus on data infrastructure, deliver reliable and resilient applications, spread software engineering best practice.
Sanhe
Launch a ready-to-code Wagtail Live development environment with a single click.

Wagtail Live Gitpod Launch a ready-to-code Wagtail Live development environment with a single click. Steps: Click the Open in Gitpod button. Relax: a

Coen van der Kamp 6 Oct 29, 2021
VSCode Development Container Template

VSCode Development Container Template This template enables you to use a full-fledged containerized development environment for your machine learning

Paige Bailey 10 Oct 10, 2022
VSCode extension to sort and refactor python imports using reorder-python-imports.

reorder-python-imports VSCode extension to sort and refactor python imports using reorder-python-imports. Unlike other import organizers, reorder-pyth

Ryan Butler 3 Aug 26, 2022
Python Indent - Correct python indentation in Visual Studio Code.

Python Indent Correct python indentation in Visual Studio Code. See the extension on the VSCode Marketplace and its source code on GitHub. Please cons

Kevin Rose 57 Dec 15, 2022
Gaphor is a UML and SysML modeling application written in Python.

Gaphor is a UML and SysML modeling application written in Python. It is designed to be easy to use, while still being powerful. Gaphor implements a fully-compliant UML 2 data model, so it is much more than a picture drawing tool. You can use Gaphor to quickly visualize different aspects of a system as well as create complete, highly complex models.

Gaphor 1.3k Jan 7, 2023
notebookJS: seamless JavaScript integration in Python Notebooks

notebookJS enables the execution of custom JavaScript code in Python Notebooks (Jupyter Notebook and Google Colab). This Python library can be useful for implementing and reusing interactive Data Visualizations in the Notebook environment.

jorgehpo 146 Dec 7, 2022
Mu - A Simple Python Code Editor

A small, simple editor for beginner Python programmers. Written in Python and Qt5.

Mu 1.2k Jan 3, 2023
A GitHub Action hosted Python IDE!

What is this ? This is an IDE running on GitHub Actions which can help in..... Running small snippets. Running codes whenever PC is not available and

Jainam Oswal 21 Nov 9, 2022
Python 3 patcher for Sublime Text v4107-4114 Windows x64

sublime-text-4-patcher Python 3 patcher for Sublime Text v4107-4114 Windows x64 Credits for signatures and patching logic goes to https://github.com/l

null 187 Dec 27, 2022
Python IDE or notebook to generate a basic Kepler.gl data visualization

geospatial-data-analysis [readme] Use this code in your Python IDE or notebook to generate a basic Kepler.gl data visualization, without pre-configura

null 2 Sep 5, 2022