Streamlit GO
Package for loading a script before streamlit server start
This package will load stgo.py in current working directory before the streamlit server starts. You can use this to patch the streamlit server or to load some data before the server starts!
For example:
- add some code before each page run
- add a custom endpoint to the streamlit server
- get current authenticated user info by custom header
Installation
pip install streamlitgo
Usage
Just create your own stgo.py in your working directory and use streamlitgo instead of streamlit in your command line.
streamlitgo run your_script.py
Example
This example shows how to log each script rerun with the user email and remote ip.
stgo.py:
import signal
import typing as T
import streamlit.runtime.app_session
import streamlit.web.bootstrap
import streamlit.web.server
from streamlit.logger import get_logger
from streamlit.runtime.scriptrunner.script_cache import ScriptCache
from streamlit.runtime.scriptrunner.script_run_context import ScriptRunContext
from streamlit.user_info import _get_user_info
from streamlit.web.server import Server
from streamlit.web.server.browser_websocket_handler import BrowserWebSocketHandler
logger = get_logger(__name__)
class MyScriptCache(ScriptCache):
def get_bytecode(self, script_path: str) -> T.Any:
user = _get_user_info()
email = user.get("email", "")
remote_ip = user.get("remote_ip", "")
logger.info(f"{email} [{remote_ip}] access script {script_path}")
return super().get_bytecode(script_path)
streamlit.runtime.runtime.ScriptCache = MyScriptCache
class MyBrowserWebSocketHandler(BrowserWebSocketHandler):
def open(self, *args, **kwargs) -> T.Awaitable[None] | None:
ret = super().open(*args, **kwargs)
session = self._runtime._session_mgr.get_session_info(self._session_id).session
email = self.request.headers.get("x-auth-request-user", "bob@Alice.com")
remote_ip = self.request.headers.get("X-Real-IP", "192.168.1.1")
user = session._user_info
user["email"] = email
user["remote_ip"] = remote_ip
return ret
class StreamlitServer(Server):
def _create_app(self):
app = super()._create_app()
rules = app.wildcard_router.rules
for rule in rules:
if issubclass(rule.target, BrowserWebSocketHandler):
rule.target = MyBrowserWebSocketHandler
break
return app
streamlit.web.bootstrap.Server = StreamlitServer
Metadata
Release files for streamlitgo 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlitgo-0.1.5.tar.gz | 201.1 kB | Without provenance | Details for streamlitgo-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlitgo-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for streamlitgo-0.1.5-py3-none-any.whl |
Total release size: 205.4 kB
Release files / streamlitgo-0.1.5.tar.gz
| Download URL | streamlitgo-0.1.5.tar.gz |
|---|---|
| Size | 201.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91b0ca794befb93b960d9dbc6ae1681df661702d93b3ffea93cc5cb11b6e3597
|
|
BLAKE2b-256 checksum How to use checksums |
44c127582c55b1061d7895b73e5c2320e18bd802b74e2b1564dc8dec7ae7e2f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / streamlitgo-0.1.5-py3-none-any.whl
| Download URL | streamlitgo-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8bbfffa59129dee2819c9e11e454d4617913b375b5c528ebb892d4bcc8015af
|
|
BLAKE2b-256 checksum How to use checksums |
4df8508b88c6fda586303d8c4fdb0d2222f483f740e3e29dbf61f8fe213c457b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for streamlitgo 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.