{"id":19054373,"url":"https://github.com/datadog/cloudcraft-python","last_synced_at":"2025-04-24T03:14:26.326Z","repository":{"id":220997789,"uuid":"748777279","full_name":"DataDog/cloudcraft-python","owner":"DataDog","description":"Python client for the Cloudcraft developer API.","archived":false,"fork":false,"pushed_at":"2025-01-17T19:15:04.000Z","size":117,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-24T03:14:20.042Z","etag":null,"topics":["api-client","cloudcraft","python","python3","sdk","sdk-python"],"latest_commit_sha":null,"homepage":"http://www.cloudcraft.co/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DataDog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-3rdparty.csv","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-26T18:36:10.000Z","updated_at":"2025-04-23T06:43:21.000Z","dependencies_parsed_at":"2024-07-09T17:11:32.131Z","dependency_job_id":null,"html_url":"https://github.com/DataDog/cloudcraft-python","commit_stats":null,"previous_names":["datadog/cloudcraft_python"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fcloudcraft-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fcloudcraft-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fcloudcraft-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fcloudcraft-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DataDog","download_url":"https://codeload.github.com/DataDog/cloudcraft-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250552076,"owners_count":21449165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","cloudcraft","python","python3","sdk","sdk-python"],"created_at":"2024-11-08T23:38:04.508Z","updated_at":"2025-04-24T03:14:26.308Z","avatar_url":"https://github.com/DataDog.png","language":"Python","readme":"# Cloudcraft API Client for Python\n\n[![License: Apache 2.0](https://img.shields.io/badge/License-Apache2.0-yellow.svg)](LICENSE.md)\n[![versions](https://img.shields.io/pypi/pyversions/cloudcraftco)](https://www.python.org/downloads/release/python-3100/)\n[![Build Status](https://github.com/DataDog/cloudcraft-python/actions/workflows/build.yaml/badge.svg?branch=main)](https://github.com/DataDog/cloudcraft-python/actions?query=branch%3Amain)\n\n![Cloudcraft diagram](https://static.cloudcraft.co/sdk/cloudcraft-sdk-example-1.svg)\n\nVisualize your cloud architecture with Cloudcraft by Datadog, [the best way to create smart AWS and Azure diagrams](https://www.cloudcraft.co/).\n\nCloudcraft supports both manual and programmatic diagramming, as well as automatic reverse engineering of existing cloud environments into\nbeautiful system architecture diagrams.\n\nThis `cloudcraftco` Python library provides an easy-to-use native Python SDK for interacting with [the Cloudcraft API](https://developers.cloudcraft.co/).\n\nUse case examples:\n- 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 pipeline\n- Download an inventory of all your cloud resources from a linked account as JSON\n- Write a converter from a third party data format to Cloudcraft diagrams\n- Backup, export \u0026 import your Cloudcraft data\n- Programmatically create Cloudcraft diagrams\n\nThis SDK requires a [Cloudcraft API key](https://developers.cloudcraft.co/#authentication) to use. [A free trial of Cloudcraft Pro](https://www.cloudcraft.co/pricing) with API access is available.\n\n## Requirements\n\n - Python 3.10\n - Requests 2.28\n\n## Installation\n\n```\npython3.10 -m pip install cloudcraftco\n```\n\n## Usage\n\nThe API is accessed through the `Cloudcraft` class. An API key available through the Cloudcraft user interface is required when instantiating `Cloudcraft`. It can be passed to the class as an argument or through the `CLOUDCRAFT_API_KEY` environment variable:\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\nprofile = cloudcraft.read_user_profile()\n```\n\n### Configuration\n\n#### Initialize with config object\n\nThe package can be initialized with several options:\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\ncloudcraft = Cloudcraft({\"api_key\": \"api-key-value\", \"timeout\": 30000})\n```\n\n`api_key` must be provided via config object or environment variable.\n\n| Option              | Default               | Description                                     |\n| ------------------- | --------------------- | ----------------------------------------------- |\n| `api_key`           |                       | API Key associated with Cloudcraft account      |\n| `maxNetworkRetries` | 10                    | The amount of times a request should be retried |\n| `timeout`           | 80000                 | Maximum time each request can take in ms        |\n| `host`              | `'api.cloudcraft.co'` | Host that requests are made to                  |\n| `port`              | 443                   | Port that requests are made to                  |\n| `protocol`          | `'https'`             | `'https'` or `'http'`                           |\n\n\nOptions may also be specified by environment variable...\n\n| Option              | Environment Variable                |\n| ------------------- | ----------------------------------- |\n| `api_key`           | `CLOUDCRAFT_API_KEY`                |\n| `maxNetworkRetries` | `CLOUDCRAFT_MAX_NETWORK_RETRIES`    |\n| `timeout`           | `CLOUDCRAFT_TIMEOUT`                |\n| `host`              | `CLOUDCRAFT_HOST`                   |\n| `port`              | `CLOUDCRAFT_PORT`                   |\n| `protocol`          | `CLOUDCRAFT_PROTOCOL`               |\n\n### Blueprints\n\n#### List blueprints\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\nblueprints = cloudcraft.list_blueprints()\n```\n\n#### Retrieve blueprint\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\nblueprint_id = \"BLUEPRINT-ID\" # valid blueprint uuid\nblueprint = cloudcraft.read_blueprint(blueprint_id)\n```\n\n#### Create blueprint\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\ndata = {\"data\": {\"grid\": \"standard\", \"name\": \"New blueprint\"}}\nblueprint = cloudcraft.create_blueprint(data)\n```\n\n#### Update blueprint\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\nblueprint_id = \"BLUEPRINT-ID\" # valid blueprint uuid\ndata = {\"data\": {\"grid\": \"standard\", \"name\": \"Updated blueprint\"}}\ncloudcraft.update_blueprint(blueprint_id, data)\n```\n\n#### Delete blueprint\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\nblueprint_id = \"BLUEPRINT-ID\" # valid blueprint uuid\ncloudcraft.delete_blueprint(blueprint_id)\n```\n\n#### Export blueprint as image\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\nscript_dir = os.path.dirname(os.path.realpath(__file__)) + os.sep\n\nbp_id = \"BLUEPRINT-ID\" # valid blueprint uuid\nbp_format = \"svg\"\nbp_file = script_dir + bp_id + \".\" + bp_format\nexport = cloudcraft.export_blueprint(bp_id, bp_format)\n\nwith open(bp_file, \"wb\") as binary_file:\n    binary_file.write(export)\n```\n\n### AWS Accounts\n\n#### Add AWS account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\n# role must exist and match your api_key/account\nrole = \"arn:aws:iam::{}:role/cloudcraft\".format(aws_account_id)\ndata = {\"name\": \"New AWS Account\", \"roleArn\": role}\nresult = cloudcraft.create_aws_account(data)\n```\n\n#### List AWS accounts\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\naccounts = cloudcraft.list_aws_accounts()\n```\n\n#### Update AWS account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\naccount_id = \"AWS-ACCOUNT\" # valid account uuid for api-key\nrole = \"AWS-ROLE\" # valid role for AWS Account\ndata = {\"name\": \"Updated Playground AWS Account\", \"roleArn\": role}\nresult = cloudcraft.update_aws_account(account_id, data)\n```\n\n#### Delete AWS account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\naccount_id = \"AWS-ACCOUNT\" # valid account uuid for api-key\ncloudcraft.delete_aws_account(account_id)\n```\n\n#### Get my AWS IAM Role parameters\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\niam_parameters = cloudcraft.read_aws_role_parameters()\n```\n\n#### Snapshot AWS account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\nscript_dir = os.path.dirname(os.path.realpath(__file__)) + os.sep\n\nss_account = \"AWS-ACCOUNT\" # valid account uuid for api-key\nss_region = \"us-west-2\"\nss_format = \"png\"\nss_file = script_dir + ss_region + \".\" + ss_format\nsnapshot = cloudcraft.snapshot_aws_account(ss_account, ss_region, ss_format)\n\nwith open(ss_file, \"wb\") as binary_file:\n    binary_file.write(snapshot)\n```\n\n### Azure Accounts\n\n#### Add Azure account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\n# id and secret values must be valid\ndata = {\n    \"name\": \"Azure Account\",\n    \"subscriptionId\": \"subscriptionId\",\n    \"directoryId\": \"directoryId\",\n    \"applicationId\": \"applicationId\",\n    \"clientSecret\": \"clientSecret\"\n}\nresult = cloudcraft.create_azure_account(data)\n```\n\n#### List Azure accounts\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\naccounts = cloudcraft.list_azure_accounts()\n```\n\n#### Update Azure account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\naccount_id = \"AZURE-ACCOUNT\" # valid account uuid for api-key\ndata = {\n    \"name\": \"Updated Azure Account\",\n    \"subscriptionId\": \"subscriptionId\",\n    \"directoryId\": \"directoryId\",\n    \"applicationId\": \"applicationId\",\n}\nresult = cloudcraft.update_azure_account(account_id, data)\n```\n\n#### Delete Azure account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\naccount_id = \"AZURE-ACCOUNT\" # valid account uuid for api-key\ncloudcraft.delete_azure_account(account_id)\n```\n\n#### Snapshot Azure account\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\nscript_dir = os.path.dirname(os.path.realpath(__file__)) + os.sep\n\nss_account = \"AZURE-ACCOUNT\" # valid account uuid for api-key\nss_location = \"canadaeast\"\nss_format = \"png\"\nss_file = script_dir + ss_location + \".\" + ss_format\nsnapshot = cloudcraft.snapshot_azure_account(ss_account, ss_location, ss_format)\n\nwith open(ss_file, \"wb\") as binary_file:\n    binary_file.write(snapshot)\n```\n\n### Budgets\n\n#### Export budget for a blueprint\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\nscript_dir = os.path.dirname(os.path.realpath(__file__)) + os.sep\n\nbp_id = \"BLUEPRINT-ID\" # valid blueprint uuid\nbp_format = \"csv\"\nbp_file = script_dir + bp_id + \".\" + bp_format\nexport = cloudcraft.export_blueprint_budget(bp_id, bp_format)\n\nwith open(bp_file, \"wb\") as binary_file:\n    binary_file.write(export)\n```\n\n### Users\n\n#### Get Cloudcraft account info\n\n```python\nfrom cloudcraftco.cloudcraft import Cloudcraft\n\n# assumes CLOUDCRAFT_API_KEY exported\ncloudcraft = Cloudcraft()\n\nprofile = cloudcraft.read_user_profile()\n```\n\n\n## More information\n\nSee the [Cloudcraft Developer API docs](https://developers.cloudcraft.co/).\n\n\n## Development\n\n### Host Environment\n\n`cloudcraft-python` was developed using...\n\n  - Python 3.7.15\n  - Poetry 1.1.14\n  - Tox 3.25.1\n\nHost environment was macOS 12, but the other environments should work.\n\nEarlier versions may work, but Python 3.10 is minimum supported version.\n\n### Running Playground (Examples)\n\nDevelopment examples showing how Cloudcraft API works running source code.\n\nTesting accounts requires care, since creating an account requires valid role.\n\n```\n% cd {repo-directory}\n% poetry env use python3.10\n% poetry shell\n% poetry install\n% export CLOUDCRAFT_API_KEY={{ api-key }}\n% python3 dev_playgrounds/blueprints.py\n% python3 dev_playgrounds/budgets.py\n% python3 dev_playgrounds/exports.py\n% python3 dev_playgrounds/snapshots_aws.py\n% python3 dev_playgrounds/snapshots_azure.py\n% python3 dev_playgrounds/users.py\n% export CLOUDCRAFT_TEST_ROLE={{ your-role-arn }}\n% python3 dev_playgrounds/accounts_aws.py\n% export CLOUDCRAFT_TEST_SUBSCRIPTION={{ your-subscription-id }}\n% export CLOUDCRAFT_TEST_DIRECTORY={{ your-directory-id }}\n% export CLOUDCRAFT_TEST_APPLICATION={{ your-application-id }}\n% export CLOUDCRAFT_TEST_SECRET={{ your-client-secret }}\n% python3 dev_playgrounds/accounts_azure.py\n```\n\n### Running Tests\n\n```\n% poetry run pytest tests/unit\n% poetry run pytest tests/functional\n% tox\n```\n\n### Formatting Code\n\n```\n% poetry run isort . --profile black\n% poetry run black .\n```\n\n### Checking Test Coverage\n\n```\n% poetry run coverage run --source=cloudcraftco --branch -m pytest .\n% poetry run coverage html\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatadog%2Fcloudcraft-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatadog%2Fcloudcraft-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatadog%2Fcloudcraft-python/lists"}