diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.streamlit/config.toml b/.streamlit/config.toml new file mode 100644 index 0000000..7c56084 --- /dev/null +++ b/.streamlit/config.toml @@ -0,0 +1,19 @@ +[client] +showErrorDetails = false +toolbarMode = "viewer" + +[runner] +magicEnabled = true + +[server] +port = 8501 + +[browser] +serverPort = 8501 + +[theme] +base = "dark" +primaryColor = "#a6d189" +backgroundColor="#232634" +secondaryBackgroundColor="#303446" +textColor="#e78284" \ No newline at end of file diff --git a/.streamlit/secrets.toml b/.streamlit/secrets.toml new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b2a5463 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# Streamlit Base + +## Intended Use + +### Gist + +This is a *template repository*, so its intended use is to create other repositories which **build off of this web app template**. + +### Use cases + +Set up by default with an **authentication system** - this is suited for general websites, but of course also works for data display apps. + + +## Dependencies + +### Pip Packages + +All pip requirements are listed in *`requirements.txt`* + + +## Authentication + +### Authentication Widgets + +Uses streamlit-authenticator library for authentication widgets + +### Credentials + +Credentials are stored in *`config.yaml`* + + +## Config && Secrets + +### Config + +Configuration for Streamlit is stored in *`/.streamlit/config.toml`* + +### Secrets + +Secrets for Streamlit environment are stored in *`/.streamlit/secrets.toml`* + + +## Github Actions + +### Pylint + +Default Pylint Github Action is set up in *`/.github/workflows/pylint.yml`* + + +## Licensing + +### None (ish). + +Unlicensed using **`https://unlicense.org/`** - see *`UNLICENSE`* file diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/UNLICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..92b2159 --- /dev/null +++ b/config.yaml @@ -0,0 +1,14 @@ +cookie: + expiry_days: 0 + key: credentials_key + name: credentials +credentials: + usernames: + example: # delete after first user is created + email: test@example.com + logged_in: false + name: Example + password: $bVAxa0JEenI1TkdGdnl2Uw$8qbxUe51emMU4d2VFeJivw +preauthorized: + emails: + - test@example.com \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dc7066d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +streamlit +extra-streamlit-components +streamlit-authenticator diff --git a/streamlit_app.py b/streamlit_app.py new file mode 100644 index 0000000..2fc11cb --- /dev/null +++ b/streamlit_app.py @@ -0,0 +1,57 @@ +""" Main Streamlit site file """ + +from yaml.loader import SafeLoader +import yaml + +import streamlit as st +import streamlit_authenticator as stauth + +# Uncomment below if you need cookies: +# import extra_streamlit_components as stx + +# Config page +PAGE_TITLE = "" +PAGE_ICON = "" +st.set_page_config( + PAGE_TITLE, PAGE_ICON, layout="wide", initial_sidebar_state="collapsed" +) +# + +# Checks for empty variables +if not PAGE_TITLE: + raise ValueError( + "Please set the PAGE_TITLE variable to the title of your app") + +if not PAGE_ICON: + raise ValueError( + "Please set the PAGE_ICON variable to the icon of your app") +# + +with open('config.yaml', 'r', encoding="utf-8") as file: + config = yaml.load(file, Loader=SafeLoader) + +authenticator = stauth.Authenticate( + config['credentials'], + config['cookie']['name'], + config['cookie']['key'], + config['cookie']['expiry_days'], + config['preauthorized'] +) + +authenticator.login() + +auth_state = st.session_state["authentication_status"] +if auth_state is False or auth_state is None: + st.error('Username/password is incorrect') + try: + email, username, name = authenticator.register_user( + preauthorization=False) + if email: + st.success('User registered successfully') + with open('config.yaml', 'w', encoding="utf-8") as file: + yaml.dump(config, file, default_flow_style=False) + except Exception as e: + st.error(e) +else: + # LOGGED IN CONTENT + pass diff --git a/workflows/pylint.yml b/workflows/pylint.yml new file mode 100644 index 0000000..17350b1 --- /dev/null +++ b/workflows/pylint.yml @@ -0,0 +1,24 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + pip install -r requirements.txt + - name: Analysing the code with pylint + run: | + pylint -d W0703 $(git ls-files '*.py')