What function should I use If I want to visualize folder structure?

I am making a project which has a visualizing github repository folder structure with interactive.
I want to visualize the folder structure and show it to you, but I can’t decide which library and tool to use.

I found some python library for visualizing like graphviz or pyvis.
But I want something beautifual or interactive visualizing

Is there any recommended tools or libraries for beautiful visualing folder structure ?
I’m now thinking about visualizing like tree

1 Like

Hey @aza1200, welcome to our Streamlit Community!

Interesting question!

I created a simple app that visualizes the entire directory structure in Github, including subfolders.

Have a look at this demo:

Export-1689663881243

Also, the code is here:

import requests
import streamlit as st


@st.cache_data()
def get_github_content(user, repo, path=''):
    url = f'https://api.github.com/repos/{user}/{repo}/contents/{path}'
    response = requests.get(url)
    return response.json()

def print_directory_structure(user, repo, path=''):
    contents = get_github_content(user, repo, path)
    for item in contents:
        if item['type'] == 'dir':
            st.write(f'Directory: {item["path"]}')
            print_directory_structure(user, repo, item['path'])
        else:
            st.write(f'File: {item["path"]}')

user = st.text_input('GitHub User:')
repo = st.text_input('GitHub Repo:')

if user and repo:
    print_directory_structure(user, repo)

Let me know what you think.

Best,
Charly

1 Like

Oh I think it’s very useful when analyzing github …!
I think tree visualization would useful but, adding that way would be useful too!!

1 Like

Glad it helps!

I think it wouldn’t be too complex to add some sort of tree visualization from the code I shared earlier with you.

Would you like to give it a try? :slight_smile:

Charly

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.