Is there a best practice streamlit project layout? I’m playing around with https://github.com/pyscaffold/pyscaffold/ and wonder if there is a common structure people use for medium-sized apps (with tests, modules etc.)?
Cheers,
C
Is there a best practice streamlit project layout? I’m playing around with https://github.com/pyscaffold/pyscaffold/ and wonder if there is a common structure people use for medium-sized apps (with tests, modules etc.)?
Cheers,
C
Hey @cwerner,
My medium-sized Streamlit projects are the same as “most” Python projects like the pyscaffold
project, with an additional src/<project>/ui
folder where I put most of my functions/.py files that call Streamlit to display input/results for other methods of the package (for a multipage example I may have a .py file per page in ui
). Then I have a ui.py at project level which acts as the main entry point for the Streamlit app and uses functions in ui
module to access the package.
Though there are times I just sprinkle st
calls inside my package files but that has a tendency to not be very maintanable.
Also on smaller projects I just have a scripts
folder next to src
where I put some huge Streamlit scripts ahah.
Fanilo
Thanks! Would you have a GitHub repo to take a look at this? Still a bit confused with setup.cfg, relative imports and folder structure
Argh right now I don’t, they are all internal projects though that would make a good blog post hmmm…if more people are interested I’ll try and write one
but you can follow most of medium-sized Python projects and integrate Streamlit easily in it’s own file (with a main function) and folder when the package is installed. I’m a fan of the output of Audrey’s cookiecutter, and Flask in general
Keep digging, you’re on the correct path!
Fanilo
No worries @andfanilo. Happy to take a look if someone else has something in this regard but I’ll also manage by myself. Always trying to optimise my workflows/ setups …
Hey @cwerner,
I like OOP so I manage my streamlit projects like this, https://github.com/ash2shukla/streamlit-heroku this has worked pretty well for me for a fairly big sized project. Also I like to keep my graphs separate in a graphs.py in parallel to utils.py.
Hope it helps !
Thanks @ash2shukla
This looks neat. Especially the page / session state logic… Is this more or less a wrapper/ convenience tooling around the SessionState hack or does this provide more features?
Its just a wrapper decorator because I didn’t like the idea of doing get_state and sync in main file, specially if you are working with some individuals who might find these lines unnecessary and might end up commenting them out eventually breaking your whole application. ( Happened with me )
Hi @andfanilo , I was wondering the same thing. As the streamlit apps get more complicated(multiple pages, ~14+ expanders per page, etc) a standard design pattern or recommendations would be really helpful
SK
@cwerner, I created a streamlit demo project by using scaffold. Find the example project here. It’s still not perfect right now as Streamlit makes it hard to build streamlit apps that can be properly packaged and installed. Thus, I created this Github issue to hopefully improve on this situation.
Hello @andfanilo,
I was wondering if you use this structure, also for comunity cloud, since in that case I would be interested in understanding how you make the package work (PYTHONPATH, setup etc… ?)
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.