Package: cloudcraftco
Cloudcraft API Client for PythonVisualize your cloud architecture with Cloudcraft by Datadog,the best way to create smart AWS and Azure diagrams.Cloudcraft supports both manual and programmatic diagramming, as well as automatic reverse engineering of existing cloud environments into
beautiful system architecture diagrams.ThiscloudcraftcoPython library provides an easy-to-use native Python SDK for interacting withthe Cloudcraft API.Use case examples:Snapshot and visually compare your live AWS or Azure environment before and after a deployment, in your app or as part of your automated CI pipelineDownload an inventory of all your cloud resources from a linked account as JSONWrite a converter from a third party data format to Cloudcraft diagramsBackup, export & import your Cloudcraft dataProgrammatically create Cloudcraft diagramsThis SDK requires aCloudcraft API keyto use.A free trial of Cloudcraft Prowith API access is available.RequirementsPython 3.10Requests 2.28Installationpython -m pip install cloudcraftcoUsageThe API is accessed through theCloudcraftclass. An API key available through the Cloudcraft user interface is required when instantiatingCloudcraft. It can be passed to the class as an argument or through theCLOUDCRAFT_API_KEYenvironment variable:fromcloudcraftcoimportCloudcraftcloudcraft=Cloudcraft()profile=cloudcraft.read_user_profile()ConfigurationInitialize with config objectThe package can be initialized with several options:fromcloudcraftcoimportCloudcraftcloudcraft=Cloudcraft({"api_key":"api-key-value","timeout":30000})api_keymust be provided via config object or environment variable.OptionDefaultDescriptionapi_keyAPI Key associated with Cloudcraft accountmaxNetworkRetries10The amount of times a request should be retriedtimeout80000Maximum time each request can take in mshost'api.cloudcraft.co'Host that requests are made toport443Port that requests are made toprotocol'https''https'or'http'Options may also be specified by environment variable...OptionEnvironment Variableapi_keyCLOUDCRAFT_API_KEYmaxNetworkRetriesCLOUDCRAFT_MAX_NETWORK_RETRIEStimeoutCLOUDCRAFT_TIMEOUThostCLOUDCRAFT_HOSTportCLOUDCRAFT_PORTprotocolCLOUDCRAFT_PROTOCOLBlueprintsList blueprintscloudcraft=Cloudcraft()blueprints=cloudcraft.list_blueprints()Retrieve blueprintcloudcraft=Cloudcraft()blueprint_id="BLUEPRINT-ID"# valid blueprint uuidblueprint=cloudcraft.read_blueprint(blueprint_id)Create blueprintcloudcraft=Cloudcraft()data={"data":{"grid":"standard","name":"New blueprint"}}blueprint=cloudcraft.create_blueprint(data)Update blueprintcloudcraft=Cloudcraft()blueprint_id="BLUEPRINT-ID"# valid blueprint uuiddata={"data":{"grid":"standard","name":"Updated blueprint"}}cloudcraft.update_blueprint(blueprint_id,data)Export blueprint as imagecloudcraft=Cloudcraft()script_dir=os.path.dirname(os.path.realpath(__file__))+os.sepbp_id="BLUEPRINT-ID"# valid blueprint uuidbp_format="svg"bp_file=script_dir+bp_id+"."+bp_formatexport=cloudcraft.export_blueprint(bp_id,bp_format)withopen(bp_file,"wb")asbinary_file:binary_file.write(export)Delete blueprintcloudcraft=Cloudcraft()blueprint_id="BLUEPRINT-ID"# valid blueprint uuidcloudcraft.delete_blueprint(blueprint_id)AWS AccountsAdd AWS accountcloudcraft=Cloudcraft()# role must exist and match your api_key/accountrole="arn:aws:iam::{}:role/cloudcraft".format(aws_account_id)data={"name":"New AWS Account","roleArn":role}result=cloudcraft.create_aws_account(data)List AWS accountscloudcraft=Cloudcraft()accounts=cloudcraft.list_aws_accounts()Snapshot AWS accountcloudcraft=Cloudcraft()script_dir=os.path.dirname(os.path.realpath(__file__))+os.sepss_account="AWS-ACCOUNT"# valid account uuid for api-keyss_region="us-west-2"ss_format="png"ss_file=script_dir+ss_region+"."+ss_formatsnapshot=cloudcraft.snapshot_aws_account(ss_account,ss_region,ss_format)withopen(ss_file,"wb")asbinary_file:binary_file.write(snapshot)Update AWS accountcloudcraft=Cloudcraft()account_id="AWS-ACCOUNT"# valid account uuid for api-keyrole="AWS-ROLE"# valid role for AWS Accountdata={"name":"Updated Playground AWS Account.","roleArn":role}result=cloudcraft.update_aws_account(account_id,data)Delete AWS accountcloudcraft=Cloudcraft()account_id="AWS-ACCOUNT"# valid account uuid for api-keycloudcraft.delete_aws_account(account_id)Get my AWS IAM Role parameterscloudcraft=Cloudcraft()iam_parameters=cloudcraft.read_aws_role_parameters()BudgetsExport budget for a blueprintcloudcraft=Cloudcraft()script_dir=os.path.dirname(os.path.realpath(__file__))+os.sepbp_id="BLUEPRINT-ID"# valid blueprint uuidbp_format="csv"bp_file=script_dir+bp_id+"."+bp_formatexport=cloudcraft.export_blueprint_budget(bp_id,bp_format)withopen(bp_file,"wb")asbinary_file:binary_file.write(export)UsersGet Cloudcraft account infocloudcraft=Cloudcraft()profile=cloudcraft.read_user_profile()More informationSee theCloudcraft Developer API docs.DevelopmentHost Environmentcloudcraft-pythonwas developed using...Python 3.7.15Poetry 1.1.14Tox 3.25.1Host environment was macOS 12, but the other environments should work.Earlier versions may work, but Python 3.10 is minimum supported version.Running Playground (Examples)Development examples showing how Cloudcraft API works running source code.Testing accounts requires care, since creating an account requires valid role.% cd {repo-directory}
% poetry env use python3.10
% poetry shell
% export CLOUDCRAFT_API_KEY={{ api-key }}
% export CLOUDCRAFT_TEST_ROLE={{ your-test-role-arn }}
% python3 dev_playgrounds/accounts.py
% python3 dev_playgrounds/blueprints.py
% python3 dev_playgrounds/budgets.py
% python3 dev_playgrounds/exports.py
% python3 dev_playgrounds/snapshots.py
% python3 dev_playgrounds/users.pyRunning Tests% poetry run pytest tests/unit
% poetry run pytest tests/functional
% toxFormatting Code% poetry run isort . --profile black
% poetry run black .Checking Test Coverage% poetry run coverage run --source=cloudcraftco --branch -m pytest .
% poetry run coverage html