Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ A blank [Streamlit](https://streamlit.io) app, plus the council district boundar
| `scripts/gemini.py` | `client()` returns a Gemini client for writing summaries ahead of time. It reads `GEMINI_API_KEY` from `.env` (copy `.env.example`). |
| `tests/` | [pytest](https://docs.pytest.org) tests. `test_app.py` checks the app starts without errors. |

The Census data source comes in a separate pull request: the BigQuery sandbox or the Census API. Merge one.
### Census data: BigQuery sandbox

`scripts/bigquery.py` has `client()`, a [BigQuery](https://cloud.google.com/bigquery/docs/sandbox) client for the team project. Google hosts Census data as [public datasets](https://console.cloud.google.com/marketplace/browse?filter=solution-type:dataset&q=census), for example `bigquery-public-data.census_bureau_acs` (American Community Survey) and `bigquery-public-data.geo_census_blockgroups` (block group shapes). Check which survey year a table covers before you use it; some are several years old.

Sign in once: install the [gcloud CLI](https://cloud.google.com/sdk/docs/install), then run `gcloud auth application-default login` with the Google account you gave on the team form.

```python
from bigquery import client

df = (
client()
.query("SELECT ... FROM `bigquery-public-data.census_bureau_acs....`")
.to_dataframe()
)
```

The sandbox is free with limits (10 GB storage, 1 TB of queries a month) and tables expire after 60 days, so save results to `data/`.

## Run it locally

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ dependencies = [

[dependency-groups]
dev = [
"db-dtypes>=1.8.0",
"geopandas>=1.2.0",
"google-cloud-bigquery>=3.46.2",
"google-genai>=2.31.0",
"pytest>=9.1.1",
"python-dotenv>=1.2.4",
Expand Down
13 changes: 13 additions & 0 deletions scripts/bigquery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""BigQuery for scripts, using the free sandbox (no billing account needed).

Sign in once with `gcloud auth application-default login` (install the gcloud CLI first:
https://cloud.google.com/sdk/docs/install). Queries run in, and count against, the team project.
"""

from google.cloud import bigquery

PROJECT = "g311-communication-needs-map"


def client() -> bigquery.Client:
return bigquery.Client(project=PROJECT)
Loading
Loading