# Generating Heroku App Inventory Lists (CSV) using Python/Pandas

When migrating thousands of containers across dozens of teams to Kubernetes or Dockerized environments, it can really help to have an inventory list which describes all the running services on all slugs in the ecosystem. \
\
\
Here's a python script that will do just that:

```
import requests

import pandas as pd

import csv

 

API_KEY = 'HRKU-API-Token' #get a token from your user profile settings

team_ids = ['dev-test-team’, ‘any-number-of-teams-here-comma-separated’]

 

all_apps_data = []

headers = {

    "Accept": "application/vnd.heroku+json; version=3",

    "Authorization": f"Bearer {API_KEY}",

}

 

# Loop through each team ID and fetch config data

for team_id in team_ids:

    response = requests.get(f'https://api.heroku.com/teams/{team_id}/apps', headers=headers)

    apps = response.json()

    for app in apps:

        app_id = app['id']

        response = requests.get(f'https://api.heroku.com/apps/{app_id}/dynos', headers=headers)

        dynos = response.json()

        response = requests.get(f'https://api.heroku.com/apps/{app_id}/addons', headers=headers)

        addons = response.json()

        for dyno in dynos:

            dyno_data = {

                'app_id': app_id,

                'app_name': app['name'],

                'dyno_id': dyno['id'],

                'dyno_size': dyno['size'],

                'dyno_type': dyno['type'],

                'addons': ', '.join([f"{addon['name']} ({addon['plan']['name']})" for addon in addons]),

            }

            all_apps_data.append(dyno_data)

 

#organize data

df = pd.DataFrame(all_apps_data)

df.to_csv('heroku_apps_data.csv', index=False)
```

Output is in this format (CSV): <br>

| app\_id | app\_name | dyno\_id   | dyno\_size | dyno\_type  | addons                                                                                    |
| ------- | --------- | ---------- | ---------- | ----------- | ----------------------------------------------------------------------------------------- |
| UUID    | Name01    | dyno\_UUID | Basic      | proc\_name0 | postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN) |
| UUID    | Name01    | dyno\_UUID | Basic      | web         | postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN) |
| UUID    | Name02    | dyno\_UUID | Basic      | web         | postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN) |
| UUID    | Name02    | dyno\_UUID | Basic      | proc\_name0 | postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN) |

If you're looking to migrate from Heroku into AKS, GKE, EKS, or some other Kubernetes solution, we've got your back. Reach out to talk to our certified experts for your next cloud migration project.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.panorbital.com/technical-solutions/generating-heroku-app-inventory-lists-csv-using-python-pandas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
