How to Structure and Organise a Streamlit App | by Andy McDonald | Feb, 2024

Editor
3 Min Read


Bringing Order to a Python Streamlit App Through an Organised Project Folder Structure

Image generated by DALLE 3 By the author. It represents going from chaos on the left to order on the right.

If you are working with a Python project that extends beyond a few simple scripts and data files, you will know the headaches that can be generated as the project grows. This can result in a cluttered folder consisting of input files, intermediate files mixed together with several Python files and / or notebook files, and even project documentation. This can make it hard to find the data or the functions you need when you are looking for it.

There are numerous articles out there detailing how to structure Python projects, which are very well-detailed. However, when it comes to Streamlit (one of my favourite Python tools for developing web-based apps very quickly) I had trouble finding information on how best to structure a Streamlit app.

As a result, I have put together this article to suggest one possible way of structuring your Streamlit app to prevent it from becoming a tangled mess of files.

The Streamlit App folder structure and the Streamlit cookiecutter template proposed here are not the only ways an app could be structured. There are numerous other factors to consider, such as the type of app you are building and who that app is for. I encourage you to use the suggestions in this article for your own app and adapt it to suit your needs.

When I am starting with Streamlit — especially when I don’t fully know what I want to achieve or if I am experimenting — I will often start with a simple directory and a single app.py file.

streamlit_app 
└── app.py

This is great, as we can put all of our code into app.py and then call upon the command streamlit run app.py to start the app in the browser.

This simple folder and single file can suddenly extend to multiple files as data is gathered from the relevant sources or generated from the main app.py file.

streamlit_app
├── app.py
├── data1.csv
├── random_data_file.csv
└── output.csv
Share this Article
Please enter CoinGecko Free Api Key to get this plugin works.