Streamlit project/ folder structure for medium-sized apps?

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

1 Like

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 :wink:

1 Like

Argh right now I don’t, they are all internal projects :frowning: 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 :wink:

Keep digging, you’re on the correct path!
Fanilo

5 Likes

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 … :+1:t2:

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 ! :slight_smile:

4 Likes

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 :smiley:)

4 Likes

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 :slight_smile:

SK

1 Like

@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.

2 Likes

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… ?)