Metadata-Version: 2.4
Name: myhamilton311
Version: 0.2.0
Summary: Python client library for the MyHamilton 311 / SeeClickFix API
License: MIT License
        
        Copyright (c) 2026 Dynacy Labs
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/dynacylabs/MyHamilton_311
Project-URL: Repository, https://github.com/dynacylabs/MyHamilton_311
Project-URL: Bug Tracker, https://github.com/dynacylabs/MyHamilton_311/issues
Keywords: hamilton,311,seeclickfix,civic,api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Provides-Extra: dev
Requires-Dist: mitmproxy; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# myhamilton311

A Python library for the **MyHamilton 311** app API — the City of Hamilton, Ohio's citizen service request platform, backed by [SeeClickFix](https://seeclickfix.com).

Reverse-engineered from mitmproxy captures of the MyHamilton 311 iOS app (build 3884).

---

## Installation

```bash
pip install requests          # only runtime dependency
# or, from this repo:
pip install -e .
```

---

## Quick Start

### Unauthenticated — browse public issues

```python
from myhamilton311 import MyHamilton311Client

client = MyHamilton311Client()

# Bounding box roughly covering Hamilton, OH
issues = client.get_issues(
    min_lat=39.368, min_lng=-84.588,
    max_lat=39.432, max_lng=-84.539,
)

print(f"{issues.pagination.entries} total issues found")
for issue in issues.issues:
    print(f"[{issue.status}] #{issue.id} — {issue.summary}")
    print(f"  {issue.address}")
```

### Authenticated — profile, my issues, city notices

```python
from myhamilton311 import MyHamilton311Client, authenticate

# Opens a browser tab for CivicPlus / SeeClickFix login
token = authenticate()

client = MyHamilton311Client(access_token=token)

profile = client.get_profile()
print(f"Logged in as {profile.name} ({profile.email})")

for notice in client.get_notices_iter():
    print(f"[{notice.published_at}] {notice.sender}: {notice.subject}")
```

If you already have a token (e.g. from a mitmproxy capture), supply it directly:

```python
client = MyHamilton311Client(access_token="FvzaRk7i-HacbIx...")
```

---

## API Reference

### `MyHamilton311Client`

| Method | Auth required | Description |
|--------|:---:|-------------|
| `get_mobile_app_config()` | No | Mobile app feature flags & branding |
| `get_scf_root()` | No | SCF platform root config |
| `get_mobile_strings()` | No | Localised UI strings |
| `get_closest_city(lat, lng)` | No | Nearest SeeClickFix place |
| `get_issues(min_lat, min_lng, max_lat, max_lng, …)` | No | Issues in bounding box |
| `get_issue(issue_id)` | No | Single issue by ID |
| `get_issues_page_iter(…)` | No | Generator over all pages |
| `get_bulletin_boards(lat, lng)` | No | City bulletin boards near point |
| `get_profile()` | **Yes** | Authenticated user's profile |
| `get_my_issues(…)` | **Yes** | Issues reported by current user |
| `get_notices(…)` | **Yes** | City / org notices |
| `get_notices_iter()` | **Yes** | Generator over all notice pages |
| `build_oauth_url(state, mode)` | — | Build OAuth authorization URL |

### `authenticate(mode, port, timeout)`

Opens the system browser to complete the CivicPlus / SeeClickFix OAuth 2.0
implicit flow.  Returns the Bearer access token string.

---

## Protocol Notes

Reverse-engineered from 8 mitmproxy capture files covering:

1. **Initial app load** — `GET /scf/v1/mobile_app_config`, `GET /api/v3/bulletin_boards`
2. **Browse issues** — `GET /api/v2/issues?…bbox…`
3. **Registration** — OAuth implicit flow → CivicPlus identity provider (IDS4) → OTP email verification → accept terms
4. **Sign out** — `GET /oauth/logout` → CivicPlus backchannel logout
5. **Sign in** — Email-based lookup → CivicPlus password page → OAuth token
6. **Notices** — `GET /api/v2/profile/notices`
7. **View issue (authenticated)** — `GET /api/v2/issues/{id}?details=true`
8. **View issue (unauthenticated)** — same endpoint, no Bearer token

### Authentication flow

```
App → GET /oauth/authorize?client_id=zBmhzPX…&response_type=token&scf_login=choose
    ← 302 → /oauth/login

User enters email → POST /oauth/login
    ← 302 → /federated_logins/ids4/1118?email=…  (CivicPlus IDP)

CivicPlus handles password entry → POST /federated_logins/ids4/callback (code + id_token JWT)
    ← 302 → /oauth/authorize  (SCF exchanges code for token)
    ← 302 → com.citysourced.hamiltonoh://oauth/callback#access_token=<BEARER_TOKEN>
```

### Key constants

| Constant | Value |
|----------|-------|
| Base URL | `https://seeclickfix.com` |
| OAuth Client ID | `zBmhzPXICuENMfUUhjX2nzvvADnCnuKxLxVPmsk4s_c` |
| OAuth Redirect URI | `com.citysourced.hamiltonoh://oauth/callback` |
| Hamilton Place ID | `16830` |
| Hamilton Org ID | `1118` |
| CivicPlus IDP | `https://cpauthentication.civicplus.com` |
| iOS User-Agent | `MyHamilton%20311/3884 CFNetwork/3860.600.21 Darwin/25.5.0` |

---

## Legal

This library is for research and personal use only.  The SeeClickFix API is
proprietary.  Be respectful of rate limits and do not use this library for
scraping at scale.
