File tree Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Original file line number Diff line number Diff line change
1
+ # .streamlit/secrets.toml
2
+
3
+ [connections .cratedb ]
4
+ dialect = " crate"
5
+ host = " localhost"
6
+ port = " 4200"
7
+ username = " crate"
8
+ password = " "
Original file line number Diff line number Diff line change
1
+ # Streamlit with CrateDB Example
2
+
3
+ ## About
4
+ Demonstrate connectivity from Streamlit to CrateDB.
5
+
6
+ ## Configuration
7
+ Configure database connection address and credentials within
8
+ ` .streamlit/secrets.toml ` in your working directory. Please
9
+ make sure to use valid credentials matching your environment.
10
+
11
+ ## Usage
12
+ To start a CrateDB instance on your machine, invoke:
13
+ ``` shell
14
+ docker run -it --rm \
15
+ --publish=4200:4200 --publish=5432:5432 \
16
+ --env=CRATE_HEAP_SIZE=2g \
17
+ crate:latest -Cdiscovery.type=single-node
18
+ ```
19
+
20
+ Install dependencies.
21
+ ``` shell
22
+ pip install -r requirements.txt
23
+ ```
24
+
25
+ Invoke Streamlit to serve the application.
26
+ ``` shell
27
+ streamlit run basic_sys_summits.py
28
+ ```
29
+
30
+ ## Screenshot
31
+
32
+ Enjoy the list of mountains.
33
+
34
+ ![ image] ( https://github.com/crate/cratedb-examples/assets/453543/7dc54224-06d0-4cfb-a5e0-b216c03bf3d2 )
Original file line number Diff line number Diff line change
1
+ """
2
+ A basic Streamlit application connecting to CrateDB using SQLAlchemy.
3
+
4
+ It reads the built-in `sys.summits` table into a dataframe, and
5
+ displays its contents.
6
+
7
+ - https://docs.streamlit.io/develop/tutorials/databases
8
+ - https://cratedb.com/docs/sqlalchemy-cratedb/
9
+ """
10
+ import streamlit as st
11
+
12
+ # Set a title for the page.
13
+ st .title ("Streamlit with CrateDB Example" )
14
+
15
+ # Connect to CrateDB, and read the built-in `sys.summits` table.
16
+ conn = st .connection ("cratedb" , type = "sql" )
17
+ df = conn .query ('SELECT * FROM "sys"."summits";' , ttl = "10m" )
18
+
19
+ # Output data as dataframe and table.
20
+ st .dataframe (df )
21
+ st .table (df )
22
+
23
+ # Output data as Markdown.
24
+ for row in df .itertuples ():
25
+ st .write (f"{ row .mountain } " )
Original file line number Diff line number Diff line change
1
+ streamlit == 1.*
2
+ sqlalchemy-cratedb == 0.38.0
You can’t perform that action at this time.
0 commit comments