Skip to main content

Civic engagement library: address → reps → delivery

Project description

GovPal Reach

Civic engagement library: discover representatives from an address and deliver messages via email or web forms. Resistbot-like functionality with modular, pluggable architecture.

Project overview

GovPal Reach maps address → representatives (federal, state, local) and supports message delivery via email (Postmark) or web forms (Playwright). Users onboard via SMS/OTP (Twilio Verify, or Plivo).

  • Discovery: Geocode address (Census Geocoder), then look up reps (Google Civic, Open States, LA local).
  • Delivery: Send messages via email or submit web forms; PGQueuer for durable queue.
  • Identity: User profiles, PII encryption, SMS OTP (Twilio primary, or Plivo).
  • Orchestrator: High-level API composing discovery and delivery.

Quick start

1. Install

Requires uv (install: curl -LsSf https://astral.sh/uv/install.sh | sh).

uv sync

2. Configure environment

Copy .env.example to .env and fill in values. See SETUP.md for how to obtain credentials.

cp .env.example .env
# Edit .env with your credentials

Email delivery mode (optional): GP_DELIVERY_MODE defaults to capture (no real sends) so new installs don't send email until you explicitly enable it. Set to live to send via Postmark.

  • capture (default) – No real sends; emails are recorded in memory for inspection (e.g. tests, CI).
  • redirect – All recipients are rewritten to the comma-separated addresses in GP_TEST_RECIPIENTS; subject is tagged with [TO: original].
  • live – Production behavior via Postmark (set explicitly to send real email).

3. Run a simple example

The library is intended to be imported by a host app. Example usage:

from govpal.orchestrator.api import discover_reps_for_address, send_message_to_representatives

# Discover reps for an address
reps = discover_reps_for_address("123 Main St, Los Angeles, CA 90012")

# Send a message to one or more representatives (library adds preamble + closing)
# body = middle content only; subject, profile, phone, and list of reps
results = send_message_to_representatives(
    "Your message body here.",
    "Subject line",
    profile,  # constituent profile (first_name, last_name, email, full_address_for_display)
    phone,
    reps,     # list of rep dicts with contact_email
)
# results = [(rep, success), ...]

4. Database schema (Postgres + Alembic required)

GovPal Reach requires PostgreSQL and Alembic for Identity (OTP), queue path, and production use. There is no non-Alembic schema path.

  1. Set DATABASE_URL in your environment (e.g. in .env).

  2. In your host app's Alembic setup, add the library's versions path to version_locations so one alembic upgrade head applies both your app's and GovPal Reach's schema. Example in env.py:

    from govpal.alembic import get_versions_path
    reach_versions = str(get_versions_path())
    # Prepend or append to version_locations (e.g. [reach_versions, "alembic/versions"])
    config.set_main_option("version_locations", ...)
    
  3. Run migrations: alembic upgrade head (or your app's equivalent, e.g. python run_migrations.py).

Migrations are idempotent: after updating the govpal-reach library, running alembic upgrade head again applies any new schema changes and is safe when nothing has changed. You do not need to check whether the library had schema updates.

Modules

Module Responsibility
Discovery Address → reps (Google Civic, Open States, Census)
Delivery Email (Postmark), web forms (Playwright), queue
Identity Users, PII, SMS OTP (Twilio or Plivo)
Orchestrator High-level API: discovery, send_message_to_representatives (preamble + closing)

How to run the system

  • As a library: Import govpal in your app; configure env vars; use orchestrator API.
  • Production queue path: For durable delivery, use the queue path: create_message → optional update_messageenqueue_messages_for_address. Set GOVPAL_USE_REAL_QUEUE=1 and run the GovPal delivery worker so jobs are processed: uv run pgq run govpal.delivery.worker:create_pgqueuer --max-concurrent-tasks 2. See SETUP.md (PGQueuer section) for create_message/update_message usage and worker run command.
  • Railway: Deploy with Postgres; run the queue worker as a separate process or worker dyno; env vars set in Railway dashboard.

Using in another project

Install GovPal Reach as a dependency from PyPI (recommended for released versions):

# With uv (recommended)
uv add "govpal-reach>=0.2.2"

# Or with pip
pip install govpal-reach

To pin to a specific GitHub tag (e.g. before a version is on PyPI or to try a release tag):

uv add "govpal-reach @ git+https://github.com/YOUR_ORG/govpal-reach@v0.2.2"

Replace YOUR_ORG and the tag (v0.2.2) as needed. The import name is govpal:

from govpal.orchestrator.api import discover_reps_for_address, create_message, update_message, enqueue_messages_for_address

How to test

# Unit tests (runs in project .venv)
uv run pytest

# With coverage
uv run pytest --cov=govpal --cov-report=term-missing

# Integration tests (multi-module flows; no DB/API needed for composed-flow tests)
uv run pytest -m integration
# With DATABASE_URL and schema applied, the worker integration test also runs; without it that test is skipped.

# Linter
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/

Full test suite (lint + pytest + coverage): see TEST_PLAN_SUMMARY.md.

Documentation

  • RESEARCH_SUMMARY.md – APIs, data sources, architecture research
  • PLAN_SUMMARY.md – Implementation plan, beads, schema, modules
  • TEST_PLAN_SUMMARY.md – Testing strategy per phase
  • SETUP.md – External services, credentials, permissions; Releasing: push a v* tag and CI publishes to PyPI (Trusted Publishing), see section 13

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

govpal_reach-0.2.3.tar.gz (55.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

govpal_reach-0.2.3-py3-none-any.whl (70.7 kB view details)

Uploaded Python 3

File details

Details for the file govpal_reach-0.2.3.tar.gz.

File metadata

  • Download URL: govpal_reach-0.2.3.tar.gz
  • Upload date:
  • Size: 55.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for govpal_reach-0.2.3.tar.gz
Algorithm Hash digest
SHA256 e780f5e9176af94d820026cee34917286c815fe743c5d71112a733ff1323743a
MD5 6f7df22b2221db0a912dae4a1a6beca3
BLAKE2b-256 0e8f7b6ce39d7270a4f92e8f74d68e38daa26e1104c84b8ca15b21fc11fb0905

See more details on using hashes here.

Provenance

The following attestation bundles were made for govpal_reach-0.2.3.tar.gz:

Publisher: release.yml on BruceAndTyler/govpal-reach

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file govpal_reach-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: govpal_reach-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 70.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for govpal_reach-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba096bf2cff336439de85e80f6b9f22b65d37cc3cf013317b229ce24a9bf4d37
MD5 f20d720f453781116dd50982fe83da52
BLAKE2b-256 4c504f848f1a808288265972a0de8f9f0fb285d05fab241fd2bc6d89a18b43f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for govpal_reach-0.2.3-py3-none-any.whl:

Publisher: release.yml on BruceAndTyler/govpal-reach

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page