> For the complete documentation index, see [llms.txt](https://blog.panorbital.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.panorbital.com/technical-solutions/generating-heroku-app-inventory-lists-csv-using-python-pandas.md).

# 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;
