Skip to main content

Option #2: Explicitly set the environment variables

os.environ['OS_DEV_MODE'] = 'true' os.environ["OS_API_ENDPOINT"] = 'your-endpoint' os.environ["OS_JWT"] = "your-jwt" os.environ["OS_USER"] = "your-username" os.environ["OS_ONTOLOGY"] = "your-ontology"

with as_developer_user() as client: client.execute(query_ontology.sync, "SELECT count() FROM dtimbr.person")

@impersonating_developer_user() def my_func(client): client.execute(query_ontology.sync, "SELECT count() FROM dtimbr.person")

@impersonating_running_user() @dev_mode(os.getenv('OS_DEV_MODE')) def my_func2(client): client.execute(query_ontology.sync, "SELECT count() FROM dtimbr.person")

my_func() my_func2()


This user will print a warning whenever it is called.

**THE @dev\_mode DECORATOR**

Using the dev\_mode decorator allows an app to switch between using a production client (defined via an @impersonating\_XXX\_user decorator) and the developer client based on the OS\_DEV\_MODE environment variable. This is handy as it does not require modifying the app code to test locally.


## Additional Notes

It is recommended to always double-check that the JWT is properly refreshed, unless expiration of the JWT is desirable (e.g. for time-bound operations).

**DO NOT PASS CLIENTS AROUND IN STREAMLIT**

Streamlit shares imported modules across threads (= user sessions), which means that importing a client from a module in a streamlit page, e.g. a utility python file from your app, will cause a singular client to be used for **ALL** users interacting with that page. In other words, **clients are not thread-safe!**



❌ **DON'T**

importing a running-user client from another module

from my_utils import my_client import streamlit as st from octostar.utils.ontology import query_ontology

st.write(my_client.execute(query_ontology.sync, "SELECT * FROM dtimbr.person"))




✅ **DO**

importing the function creating the client, not the client itself

from streamlit_octostar_utils.octostar.client import as_running_user import streamlit as st from octostar.utils.ontology import query_ontology

with as_running_user() as client: st.write(client.execute(query_ontology.sync, "SELECT * FROM dtimbr.person"))