Skip to content

Commit da52c6c

Browse files
authored
[SDK: Python] Add Offices, Organizations, OTAs, OTIDVs, Subawards, NAICS, and Assistance endpoints (#12)
1 parent 720a06f commit da52c6c

32 files changed

Lines changed: 3680 additions & 46 deletions

.github/workflows/lint.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15+
16+
- name: Checkout tango API repo (manifest source)
17+
uses: actions/checkout@v4
18+
with:
19+
repository: makegov/tango
20+
path: tango-api
1521

1622
- name: Install uv
1723
uses: astral-sh/setup-uv@v4
@@ -29,3 +35,6 @@ jobs:
2935

3036
- name: Lint with ruff
3137
run: uv run ruff check tango/
38+
39+
- name: Check SDK filter/shape conformance
40+
run: uv run python scripts/check_filter_shape_conformance.py --manifest tango-api/contracts/filter_shape_contract.json

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.3.0] - 2026-02-12
11+
1012
### Added
1113

1214
### Changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,10 @@ tango-python/
432432
│ └── quick_start.ipynb # Interactive quick start
433433
├── scripts/ # Utility scripts
434434
│ ├── README.md
435+
│ ├── check_filter_shape_conformance.py # Filter + shape conformance (CI)
435436
│ ├── fetch_api_schema.py
436-
│ └── generate_schemas_from_api.py
437+
│ ├── generate_schemas_from_api.py
438+
│ └── pr_review.py # PR validation (lint, types, tests, conformance)
437439
├── pyproject.toml # Project configuration
438440
├── uv.lock # Dependency lock file
439441
├── LICENSE # MIT License
@@ -471,7 +473,12 @@ Contributions are welcome! Please feel free to submit a Pull Request.
471473

472474
1. Fork the repository
473475
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
474-
3. Run tests (`uv run pytest`)
475-
4. Commit your changes (`git commit -m 'Add amazing feature'`)
476-
5. Push to the branch (`git push origin feature/amazing-feature`)
477-
6. Open a Pull Request
476+
3. Run lint and format: `uv run ruff format tango/ && uv run ruff check tango/`
477+
4. Run type checking: `uv run mypy tango/`
478+
5. Run tests: `uv run pytest`
479+
6. (Optional) Run [filter and shape conformance](scripts/README.md#filter-and-shape-conformance) if you have the tango API manifest; CI will run it on push/PR
480+
7. Commit your changes (`git commit -m 'Add amazing feature'`)
481+
8. Push to the branch (`git push origin feature/amazing-feature`)
482+
9. Open a Pull Request
483+
484+
For a single command that runs formatting, linting, type checking, and tests (and conformance when the manifest is present), use: `uv run python scripts/pr_review.py --mode full`

ROADMAP.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22

33
## Now
44

5-
- [ ] Align existing API to the SDK
6-
- [ ] Add in existing IDV endpoint
7-
- [ ] Add in existing OTA endpoint
8-
- [ ] Add in existing OTIDV endpoint
9-
- [ ] Add in existing financial assistance endpoint
10-
- [ ] Add in account usage endpoint
11-
- [ ] Add in webhooks endpoint
12-
- [ ] Add in subawards endpoint
5+
- [X] Align existing API to the SDK
136
- [ ] Better Filter DX
147
- [ ] Dataclasses for search validation and typing
158
- [ ] Docs improvements

docs/API_REFERENCE.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Complete reference for all Tango Python SDK methods and functionality.
1717
- [Business Types](#business-types)
1818
- [Webhooks](#webhooks)
1919
- [Response Objects](#response-objects)
20+
- [ShapeConfig (predefined shapes)](#shapeconfig-predefined-shapes)
2021
- [Error Handling](#error-handling)
2122

2223
## Client Initialization
@@ -904,6 +905,48 @@ print(f"Total collected: {len(all_results)} results")
904905

905906
---
906907

908+
## ShapeConfig (predefined shapes)
909+
910+
The SDK provides predefined shape strings as constants on `ShapeConfig`. Use them as the `shape` argument for list/get methods when you want a consistent, validated set of fields without building a custom shape string.
911+
912+
```python
913+
from tango import TangoClient, ShapeConfig
914+
915+
client = TangoClient()
916+
917+
# List methods default to the minimal shape when shape is omitted
918+
contracts = client.list_contracts(limit=10) # uses CONTRACTS_MINIMAL
919+
920+
# Or pass the constant explicitly
921+
contracts = client.list_contracts(shape=ShapeConfig.CONTRACTS_MINIMAL, limit=10)
922+
entity = client.get_entity("UEI_KEY", shape=ShapeConfig.ENTITIES_COMPREHENSIVE)
923+
```
924+
925+
**Available constants (by resource):**
926+
927+
| Constant | Used by | Description |
928+
|----------|---------|-------------|
929+
| `CONTRACTS_MINIMAL` | `list_contracts`, `search_contracts` | key, piid, award_date, recipient(display_name), description, total_contract_value |
930+
| `ENTITIES_MINIMAL` | `list_entities` | uei, legal_business_name, cage_code, business_types |
931+
| `ENTITIES_COMPREHENSIVE` | `get_entity` | Full entity profile (addresses, naics, psc, obligations, etc.) |
932+
| `FORECASTS_MINIMAL` | `list_forecasts` | id, title, anticipated_award_date, fiscal_year, naics_code, status |
933+
| `OPPORTUNITIES_MINIMAL` | `list_opportunities` | opportunity_id, title, solicitation_number, response_deadline, active |
934+
| `NOTICES_MINIMAL` | `list_notices` | notice_id, title, solicitation_number, posted_date |
935+
| `GRANTS_MINIMAL` | `list_grants` | grant_id, opportunity_number, title, status(*), agency_code |
936+
| `IDVS_MINIMAL` | `list_idvs`, `list_vehicle_awardees` | key, piid, award_date, recipient(display_name,uei), description, total_contract_value, obligated, idv_type |
937+
| `IDVS_COMPREHENSIVE` | `get_idv` | Full IDV with offices, place_of_performance, competition, transactions, etc. |
938+
| `VEHICLES_MINIMAL` | `list_vehicles` | uuid, solicitation_identifier, organization_id, awardee_count, order_count, vehicle_obligations, vehicle_contracts_value, solicitation_title, solicitation_date |
939+
| `VEHICLES_COMPREHENSIVE` | `get_vehicle` | Full vehicle with competition_details, fiscal_year, set_aside, etc. |
940+
| `VEHICLE_AWARDEES_MINIMAL` | `list_vehicle_awardees` | uuid, key, piid, award_date, title, order_count, idv_obligations, idv_contracts_value, recipient(display_name,uei) |
941+
| `ORGANIZATIONS_MINIMAL` | `list_organizations`, `list_organization_offices` | key, fh_key, name, level, type, short_name |
942+
| `OTAS_MINIMAL` | `list_otas` | key, piid, award_date, recipient(display_name,uei), description, total_contract_value, obligated |
943+
| `OTIDVS_MINIMAL` | `list_otidvs` | key, piid, award_date, recipient(display_name,uei), description, total_contract_value, obligated, idv_type |
944+
| `SUBAWARDS_MINIMAL` | `list_subawards` | award_key, prime_recipient(uei,display_name), subaward_recipient(uei,display_name) |
945+
946+
All predefined shapes are validated at SDK release time (see [Developer Guide](DEVELOPERS.md#sdk-conformance-maintainers)). For custom shapes, see the [Shaping Guide](SHAPES.md).
947+
948+
---
949+
907950
## Error Handling
908951

909952
The SDK provides specific exception types for different error scenarios.
@@ -1094,7 +1137,8 @@ client = TangoClient()
10941137

10951138
## Additional Resources
10961139

1097-
- [Shaping Guide](SHAPES.md) - Comprehensive guide to response shaping
1140+
- [Shaping Guide](SHAPES.md) - Response shaping syntax, examples, and field reference
1141+
- [Developer Guide](DEVELOPERS.md) - Dynamic models, predefined shapes, and SDK conformance (maintainers)
10981142
- [Quick Start](quick_start.ipynb) - Interactive notebook with examples
10991143
- [GitHub Repository](https://github.com/makegov/tango-python) - Source code and examples
11001144
- [Tango API Documentation](https://tango.makegov.com/docs) - Full API documentation

docs/DEVELOPERS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The Tango SDK uses dynamic models that generate runtime types matching the exact
1212
- [Type Hints and IDE Support](#type-hints-and-ide-support)
1313
- [Performance Considerations](#performance-considerations)
1414
- [Troubleshooting](#troubleshooting)
15+
- [SDK conformance (maintainers)](#sdk-conformance-maintainers)
1516

1617
## Overview
1718

@@ -623,6 +624,32 @@ If you encounter issues:
623624
3. See [examples/](../examples/) for working code samples
624625
4. Contact support at [tango@makegov.com](mailto:tango@makegov.com)
625626

627+
## SDK conformance (maintainers)
628+
629+
The SDK is kept in sync with the Tango API and its own shape schemas via two conformance checks. Both run in CI on every push and PR (see [Lint workflow](../.github/workflows/lint.yml)) and can be run locally with [scripts/check_filter_shape_conformance.py](../scripts/check_filter_shape_conformance.py).
630+
631+
### Filter conformance
632+
633+
- **What it checks:** Every list/get endpoint in the canonical manifest (from the [tango](https://github.com/makegov/tango) API repo) has a matching SDK method that exposes the manifest’s filter parameters—either as explicit arguments or via the method’s `api_param_mapping`.
634+
- **Why it matters:** Ensures the SDK supports all query filters the API exposes for each resource, so users can filter without relying on undocumented `**kwargs`.
635+
- **Warnings:** Methods that take filters only via `**kwargs` are reported as warnings (filter names cannot be verified against the manifest).
636+
637+
### Shape conformance
638+
639+
- **What it checks:** Every predefined shape in `ShapeConfig` (e.g. `CONTRACTS_MINIMAL`, `IDVS_MINIMAL`, `GRANTS_MINIMAL`) is parsed and validated against the SDK’s explicit schemas in `tango/shapes/explicit_schemas.py`. Each shape must only reference fields that exist for that model (including nested fields).
640+
- **Why it matters:** Ensures default shapes never reference invalid or renamed fields, so default list/get behavior stays valid after schema or API changes.
641+
- **Errors:** Parse failures or invalid field names in any `ShapeConfig` constant are reported as errors and fail the check.
642+
643+
### Running the conformance check
644+
645+
- **In CI:** The [Lint workflow](../.github/workflows/lint.yml) runs the full check automatically (it has access to the manifest). No setup needed for push/PR.
646+
- **Locally:** You need the manifest file to run the script. If you have it (e.g. a path to `filter_shape_contract.json` from the [tango](https://github.com/makegov/tango) repo—wherever you keep that repo—or from a colleague), run:
647+
```bash
648+
uv run python scripts/check_filter_shape_conformance.py --manifest /path/to/filter_shape_contract.json
649+
```
650+
If you don’t have the manifest, CI will still run the full check on your branch; shape conformance is included whenever the script runs.
651+
- **Output:** JSON with `errors` and `warnings`. Exit code 1 if there are any errors. See [scripts/README.md](../scripts/README.md#filter-and-shape-conformance) for full usage and `--list-missing`.
652+
626653
## Next Steps
627654

628655
- Read the [API Reference](API_REFERENCE.md) for detailed class and method documentation

docs/SHAPES.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Response shaping lets you control which fields the API returns, making your requests faster and more efficient. Instead of receiving hundreds of fields you don't need, you specify exactly what you want.
44

5+
**See also:** [API Reference](API_REFERENCE.md) for method parameters and [ShapeConfig (predefined shapes)](API_REFERENCE.md#shapeconfig-predefined-shapes); [Developer Guide](DEVELOPERS.md) for dynamic models and maintainer conformance.
6+
57
## Why Use Response Shaping?
68

79
**Performance Benefits:**
@@ -27,11 +29,36 @@ contracts = client.list_contracts(
2729
shape="key,piid,recipient(display_name),total_contract_value"
2830
)
2931

32+
# Or use a predefined shape constant
33+
from tango import ShapeConfig
34+
contracts = client.list_contracts(shape=ShapeConfig.CONTRACTS_MINIMAL, limit=10)
35+
3036
# Access the data
3137
for contract in contracts.results:
3238
print(f"{contract['piid']}: {contract['recipient']['display_name']}")
3339
```
3440

41+
## Predefined shapes (ShapeConfig)
42+
43+
Instead of writing shape strings by hand, you can use the SDK’s predefined constants. Each list/get method has a default minimal shape when you omit `shape`; you can also pass a constant explicitly.
44+
45+
```python
46+
from tango import TangoClient, ShapeConfig
47+
48+
client = TangoClient()
49+
50+
# These are equivalent (list_contracts defaults to CONTRACTS_MINIMAL)
51+
contracts = client.list_contracts(limit=10)
52+
contracts = client.list_contracts(shape=ShapeConfig.CONTRACTS_MINIMAL, limit=10)
53+
54+
# Other resources
55+
entities = client.list_entities(shape=ShapeConfig.ENTITIES_MINIMAL)
56+
idvs = client.list_idvs(shape=ShapeConfig.IDVS_MINIMAL)
57+
grants = client.list_grants(shape=ShapeConfig.GRANTS_MINIMAL)
58+
```
59+
60+
**Available constants:** Contracts (`CONTRACTS_MINIMAL`), Entities (`ENTITIES_MINIMAL`, `ENTITIES_COMPREHENSIVE`), Forecasts, Opportunities, Notices, Grants, IDVs, Vehicles, Organizations, OTAs, OTIDVs, Subawards. See [API Reference – ShapeConfig](API_REFERENCE.md#shapeconfig-predefined-shapes) for the full table and which method uses which constant.
61+
3562
## Basic Shaping
3663

3764
### Simple Fields
@@ -455,5 +482,6 @@ display_name = contract.get('recipient', {}).get('display_name', 'Unknown')
455482
- **Define patterns** - Create reusable shapes for your common queries
456483

457484
For more help, see:
458-
- [Quick Start Guide](quick_start.ipynb) - Interactive examples
459-
- [API Reference](API_REFERENCE.md) - Complete field listings
485+
- [API Reference](API_REFERENCE.md) - Method parameters, [ShapeConfig table](API_REFERENCE.md#shapeconfig-predefined-shapes), and field context
486+
- [Developer Guide](DEVELOPERS.md) - Dynamic models, predefined shapes in depth, and SDK conformance (for maintainers)
487+
- [Quick Start Guide](quick_start.ipynb) - Interactive examples

scripts/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ This directory contains utility scripts used during development and maintenance
1212
### Testing and Validation
1313

1414
- **`test_production.py`** - Runs production API smoke tests against the live API
15-
- **`pr_review.py`** - Runs configurable validation checks for PR review (linting, type checking, tests)
15+
- **`pr_review.py`** - Runs configurable validation checks for PR review (linting, type checking, tests, conformance)
16+
- **`check_filter_shape_conformance.py`** - Validates SDK filter and shape conformance (see [Filter and shape conformance](#filter-and-shape-conformance))
1617

1718
## Usage
1819

@@ -56,8 +57,10 @@ uv run python scripts/pr_review.py --mode production --changed-files-only
5657
**Validation Modes:**
5758
- `smoke` - Production API smoke tests only
5859
- `quick` - Linting + type checking (no tests)
59-
- `full` - All checks (linting + type checking + all tests)
60-
- `production` - Production API smoke tests + linting + type checking (default)
60+
- `full` - All checks (linting + type checking + filter/shape conformance + all tests)
61+
- `production` - Linting + type checking + filter/shape conformance + production API smoke tests (default)
62+
63+
When the conformance manifest is present (`tango-api/contracts/filter_shape_contract.json` or `TANGO_CONTRACT_MANIFEST`), both `full` and `production` run the [filter and shape conformance](#filter-and-shape-conformance) check. If the manifest is missing, that step is skipped with a warning.
6164

6265
**PR Detection:**
6366
The script automatically detects PR information from:
@@ -70,6 +73,27 @@ When a PR is detected, the script displays PR information and automatically:
7073
- Checks only changed files
7174
- Shows PR URL in summary
7275

76+
### Filter and shape conformance
77+
78+
The SDK is validated against a canonical manifest (from the [tango](https://github.com/makegov/tango) API repo) for **filter conformance** and against its own schemas for **shape conformance**:
79+
80+
1. **Filter conformance** – Ensures every list/get method exposes the filter parameters defined in the manifest (e.g. `award_date`, `naics_code`, `agency`). Methods that use `**kwargs` for filters are reported as warnings because their filter names cannot be verified.
81+
2. **Shape conformance** – Ensures every `ShapeConfig` constant (e.g. `CONTRACTS_MINIMAL`, `IDVS_MINIMAL`) parses correctly and only references fields that exist in the SDK’s explicit schemas for that model. Invalid or unknown fields in default shapes are reported as errors.
82+
83+
This script runs in CI on every push/PR (see [Lint workflow](.github/workflows/lint.yml)). The manifest file is produced by the tango API repo and must be available for the full check.
84+
85+
```bash
86+
# Full check (filter + shape). Requires manifest from tango API repo.
87+
uv run python scripts/check_filter_shape_conformance.py --manifest tango-api/contracts/filter_shape_contract.json
88+
89+
# List resources that have no matching SDK method (for implementation checklist)
90+
uv run python scripts/check_filter_shape_conformance.py --manifest tango-api/contracts/filter_shape_contract.json --list-missing
91+
```
92+
93+
**Output:** JSON with `manifest`, `errors`, and `warnings`. Exit code 1 if there are any errors (missing filters, invalid shapes, or missing SDK methods for manifest resources).
94+
95+
**Local runs:** To run the full check locally, you need a copy of `filter_shape_contract.json` (from the [tango](https://github.com/makegov/tango) repo’s `contracts/` directory—wherever you keep that repo). Pass it with `--manifest` or set `TANGO_CONTRACT_MANIFEST`. The script runs both filter and shape conformance; shape conformance validates all `ShapeConfig` defaults against `tango/shapes/explicit_schemas.py`.
96+
7397
## Requirements
7498

7599
- `TANGO_API_KEY` environment variable (required for production API tests)

0 commit comments

Comments
 (0)