Skip to content

Commit 8f17638

Browse files
authored
fix(http): replace http by web for better naming and include a preview of the web service on home page (#299)
1 parent 3c0cc47 commit 8f17638

15 files changed

Lines changed: 475 additions & 177 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pip install pysus
2323

2424
For the local Streamlit web interface:
2525
```bash
26-
pip install pysus[http]
26+
pip install pysus[web]
2727
```
2828

2929
### Docker
@@ -129,19 +129,19 @@ async def main():
129129
Launch the local web interface:
130130

131131
```bash
132-
pysus http
132+
pysus web
133133
```
134134

135135
Or with a custom port:
136136

137137
```bash
138-
pysus http -p 8080
138+
pysus web -p 8080
139139
```
140140

141141
Or run directly with Streamlit:
142142

143143
```bash
144-
streamlit run pysus/http/app.py
144+
streamlit run pysus/web/app.py
145145
```
146146

147147
The web interface provides three data sources:

docs/source/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PySUS is a Python package for accessing and analyzing Brazil's public health dat
2020
and work with health datasets including SINAN (disease notifications), SIM (mortality),
2121
SINASC (births), SIH (hospitalizations), SIA (ambulatory), CIHA, CNES, PNI, and more.
2222

23+
A local web server (`pysus web`) is included for interactive browsing and downloading
24+
of datasets through a graphical Streamlit interface.
25+
2326
This documentation covers PySUS 2.0+.
2427

2528
.. toctree::

docs/source/installation.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ Using Poetry:
6060
6161
poetry install
6262
63+
Web Interface
64+
-------------
65+
66+
PySUS includes a local Streamlit-based web server for browsing and downloading
67+
datasets interactively. Start it with:
68+
69+
.. code-block:: bash
70+
71+
pysus web
72+
73+
Or directly:
74+
75+
.. code-block:: bash
76+
77+
streamlit run pysus/web/app.py
78+
79+
This opens a browser at ``http://localhost:8501`` with a graphical interface for
80+
querying PySUS s3, DATASUS FTP, and dados.gov.br sources.
81+
6382
Configuration
6483
-------------
6584

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ exclude = [
1212
"pysus/tests/**",
1313
"pysus/management",
1414
"pysus/management/**",
15-
"pysus/http/**",
1615
]
1716

1817
[tool.poetry.dependencies]
@@ -47,7 +46,7 @@ typer = "^0.24.1"
4746
humanize = "^4.8.0"
4847

4948
[tool.poetry.extras]
50-
http = ["streamlit"]
49+
web = ["streamlit"]
5150

5251
[tool.poetry.group.dev.dependencies]
5352
pytest = ">=6.1.0"
@@ -106,7 +105,7 @@ exclude = ["*.git", "docs/"]
106105
omit = [
107106
"pysus/management/client.py",
108107
"pysus/tui/*",
109-
"pysus/http/*",
108+
"pysus/web/*",
110109
"pysus/cli/*",
111110
]
112111

pysus/cli/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def version():
1010

1111

1212
@app.command()
13-
def http(
13+
def web(
1414
port: int = typer.Option( # noqa: B008
1515
8501,
1616
"-p",
@@ -25,13 +25,13 @@ def http(
2525
except ImportError:
2626
raise ImportError(
2727
"The HTTP UI requires extra dependencies. "
28-
"Install them with: pip install pysus[http]"
28+
"Install them with: pip install pysus[web]"
2929
)
3030
import os
3131
import sys
3232
import webbrowser
3333

34-
app_path = os.path.join(os.path.dirname(__file__), "..", "http", "app.py")
34+
app_path = os.path.join(os.path.dirname(__file__), "..", "web", "app.py")
3535
app_path = os.path.abspath(app_path)
3636

3737
from streamlit.web import cli as stcli

pysus/http/app.py

Lines changed: 0 additions & 94 deletions
This file was deleted.

pysus/tests/data/test_dbf_reader.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
from datetime import date
33
from pathlib import Path
44

5-
import numpy as np
65
import pandas as pd
76
import pytest
8-
97
from pysus.data.dbf_reader import (
108
_parse_header,
119
read_dbf_fast,
@@ -14,7 +12,6 @@
1412
stream_dbf_fast,
1513
)
1614

17-
1815
# ---------------------------------------------------------------------------
1916
# Helpers
2017
# ---------------------------------------------------------------------------
@@ -85,9 +82,7 @@ def simple_dbf(tmp_dir):
8582
def wide_dbf(tmp_dir):
8683
dbf_path = tmp_dir / "wide.dbf"
8784
fields = [(f"COL{i}", "C", 8, 0) for i in range(20)]
88-
records = [
89-
tuple(f"val{i}_{j}" for j in range(20)) for i in range(100)
90-
]
85+
records = [tuple(f"val{i}_{j}" for j in range(20)) for i in range(100)]
9186
_create_dbf(dbf_path, fields, records)
9287
return dbf_path
9388

@@ -200,7 +195,6 @@ def test_read_fast_wide(wide_dbf):
200195
def test_read_fast_strips_nul_bytes(tmp_dir):
201196
dbf_path = tmp_dir / "nuls.dbf"
202197
today = date.today()
203-
fields = [("VAL", "C", 8, 0)]
204198
buf = bytearray()
205199
buf.append(0x03)
206200
buf.append(today.year - 1900)
@@ -289,15 +283,11 @@ def test_read_filtered_column_subset(disease_dbf):
289283

290284
def test_read_filtered_missing_column(disease_dbf):
291285
with pytest.raises(KeyError, match="not found"):
292-
read_dbf_filtered(
293-
disease_dbf, column="NONEXISTENT", values=["X"]
294-
)
286+
read_dbf_filtered(disease_dbf, column="NONEXISTENT", values=["X"])
295287

296288

297289
def test_read_filtered_empty_file(empty_dbf):
298-
df = read_dbf_filtered(
299-
empty_dbf, column="NAME", values=["X"]
300-
)
290+
df = read_dbf_filtered(empty_dbf, column="NAME", values=["X"])
301291
assert len(df) == 0
302292

303293

@@ -378,9 +368,7 @@ def test_large_record_count(tmp_dir):
378368

379369

380370
def test_field_name_lowercase_match():
381-
from pysus.data.dbf_reader import _find_field
382-
383-
from pysus.data.dbf_reader import DBFSchema, DBFField
371+
from pysus.data.dbf_reader import DBFField, DBFSchema, _find_field
384372

385373
schema = DBFSchema(
386374
num_records=1,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""PySUS HTTP — Streamlit-based visual interface for localhost use."""
22

3-
from pysus.http.app import home # noqa
3+
from pysus.web.app import home # noqa

0 commit comments

Comments
 (0)