Skip to content

strg-at/template-streamlit

Repository files navigation

pre-commit taskfile

Streamlit Template

This repo is a template to quick start a streamlit application for proof of concept projects

Table of Contents

Code-Style

Getting Started

This Python project is managed via Poetry, and leverages the pyproject.toml configuration file, rather than the older setup.py. The pyproject.toml configuration file can be and is also used to store 3rd party tools configurations, such as black, ruff, mypy etc.

Setup

Install the project and its poetry dependencies, by using:

poetry env use `which python 3.12`
poetry add streamlit seaborn tqdm matplotlib altair pydantic plotly numpy pandas
poetry add --group lsp-dev pylsp-mypy python-lsp-server
poetry install

Run the app without entering the virtual environment with:

poetry run streamlit run template_streamlit/main.py

Alternatively, the virtual environment can be activated with:

source ./activate.sh

or if this doesn't work try

source $(poetry env info -p)/bin/activate

And then the streamlit app can be manually run:

streamlit run template_streamlit/main.py

Using Poetry

In order to use poetry, you should install it first. If your OS package manager has a python-poetry package, you might also choose to install Poetry that way. Notice that if you do this, you should make sure that your OS also ships all the necessary plugins you might want to use (most importantly, poetry-plugin-export). As of the time of writing, Archlinux does.

Dependency management

To add a dependency, simply run:

poetry add 3rd-party-package

To remove a dependency, run:

poetry remove 3rd-party-package

To add a dev dependency, run:

poetry add dev-dep-package --group dev

In this template, we also create one (or more) additional dependency group(s) to deal with IDE specific dependencies. For instance, if you want to use the python-lsp-server, as well as installing its plugins for mypy etc., then you can use the lsp-dev group.

poetry install --with dev --with lsp-dev

Version management

Poetry has some nice shortcuts to manage the project version. You can see them by running

poetry version --help

For instance, bumping to the next minor version can be done with:

poetry version minor

This would be a project from, e.g., 1.2 to 1.3. A major bump can be done with:

poetry version major

Poetry can do more than this, consult the documentation for more information.

Streamlit

see streamlit docs for details

Commands

Look here for a cheat-sheet of commands and often used widgets

Configuration

To customize the theme or adjust rendering logic of e.g. the sidebar, create / update the .streamlit/config.toml file in your root folder. For example, as an app grows, one might want to hide the sidebar with showSidebarNavigation = true and implement their own menu.

You can also configure server, client and browser options; for all options see the docs.

Plugins and Components

Available streamlit plugins can be found here. For example for

Prerequisties

Install pre-commit.

Initialize repository

Pre-commit framework need to get initialized.

task pre-commit:init

Pre-commit

Run the following to fix linting issues using pre-commit.

task pre-commit:run

Based on pre-commit gitleaks dependencies Go language needs to be installed.

Preparation

All changes require a PR and review. Create a new branch and reference a Jira ticket, f.e.

git switch -c feature/INPRO-1-configure-resource

Known Issues