usaspending-orm 0.6.0__tar.gz → 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/PKG-INFO +38 -4
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/README.md +34 -1
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/pyproject.toml +6 -2
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/config.py +1 -1
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/agency.py +61 -70
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/award.py +31 -46
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/award_factory.py +7 -5
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/award_types.py +6 -6
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/base_model.py +52 -14
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/contract.py +63 -17
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/district_spending.py +23 -5
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/download.py +45 -5
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/funding.py +121 -25
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/grant.py +73 -15
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/idv.py +65 -20
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/lazy_record.py +30 -7
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/loan.py +40 -8
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/location.py +116 -4
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/period_of_performance.py +36 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/recipient.py +104 -12
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/recipient_business_categories.py +22 -22
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/recipient_spending.py +32 -7
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/spending.py +42 -10
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/state_spending.py +17 -5
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/subaward.py +168 -49
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/subtier_agency.py +38 -10
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/transaction.py +73 -9
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/awards_search.py +47 -10
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/filters.py +186 -47
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/funding_search.py +3 -3
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/query_builder.py +723 -175
- usaspending_orm-0.7.0/src/usaspending/queries/recipient_query.py +135 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/spending_search.py +118 -12
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/subawards_search.py +73 -4
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/transactions_search.py +123 -25
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/recipients_resource.py +20 -6
- usaspending_orm-0.7.0/src/usaspending/utils/__init__.py +13 -0
- usaspending_orm-0.7.0/src/usaspending/utils/validations.py +123 -0
- usaspending_orm-0.6.0/src/usaspending/queries/recipient_query.py +0 -66
- usaspending_orm-0.6.0/src/usaspending/utils/__init__.py +0 -6
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/LICENSE +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/__init__.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/cli/__init__.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/cli/download_award.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/client.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/download/__init__.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/download/job.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/download/manager.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/exceptions.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/logging_config.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/models/__init__.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/__init__.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/agencies_search.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/agency_award_summary.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/agency_query.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/award_query.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/awarding_agencies_search.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/funding_agencies_search.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/recipients_search.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/single_resource_base.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/queries/sub_agency_query.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/__init__.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/agency_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/award_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/base_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/download_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/funding_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/spending_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/subawards_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/resources/transactions_resource.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/utils/formatter.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/utils/rate_limit.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/utils/retry.py +0 -0
- {usaspending_orm-0.6.0 → usaspending_orm-0.7.0}/src/usaspending/utils/special_cases.yaml +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: usaspending-orm
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: A Python ORM wrapper for the USAspending.gov API with intuitive queries, automatic pagination, and smart caching
|
|
5
|
-
License: MIT
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
6
7
|
Keywords: usaspending,federal-spending,government-data,api-wrapper,orm,contracts,grants
|
|
7
8
|
Author: Casey Dreier
|
|
8
9
|
Author-email: casey.dreier@planetary.org
|
|
@@ -305,6 +306,39 @@ logging.basicConfig(
|
|
|
305
306
|
|
|
306
307
|
USASpending Python Wrapper is under active development. The API is stabilizing but may change as we refine the abstractions based on real-world usage. We welcome feedback on the interface design and feature priorities.
|
|
307
308
|
|
|
309
|
+
## Testing
|
|
310
|
+
|
|
311
|
+
The library includes both unit tests and integration tests.
|
|
312
|
+
|
|
313
|
+
### Running Unit Tests
|
|
314
|
+
|
|
315
|
+
Unit tests run against mocked API responses and do not require network access:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
# Run all unit tests (default, excludes integration tests)
|
|
319
|
+
pytest
|
|
320
|
+
|
|
321
|
+
# Run with verbose output
|
|
322
|
+
pytest -v
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Running Integration Tests
|
|
326
|
+
|
|
327
|
+
Integration tests hit the real USASpending.gov API to verify end-to-end functionality. These are **excluded by default** to avoid network dependencies during normal development.
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
# Run only integration tests
|
|
331
|
+
pytest -m integration
|
|
332
|
+
|
|
333
|
+
# Run integration tests with verbose output
|
|
334
|
+
pytest -m integration -v
|
|
335
|
+
|
|
336
|
+
# Run all tests including integration
|
|
337
|
+
pytest -m ""
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Integration tests verify connectivity and response structure for all major resources including awards, recipients, agencies, spending, and award-related data (transactions, funding, subawards).
|
|
341
|
+
|
|
308
342
|
## Contributing
|
|
309
343
|
|
|
310
344
|
We welcome contributions to improve and expand the implementation and functionality.
|
|
@@ -315,7 +349,7 @@ This library was initially developed to serve the needs of The Planetary Society
|
|
|
315
349
|
|
|
316
350
|
We have open-sourced the project to enable others to better use USASpending data.
|
|
317
351
|
|
|
318
|
-
[The Planetary Society](planetary.org) is an independent nonprofit organization that empowers the world's citizens to advance space science and exploration. The organization is supported by individuals across the world, and does not accept government grants nor does it have major aerospace donations.
|
|
352
|
+
[The Planetary Society](https://planetary.org) is an independent nonprofit organization that empowers the world's citizens to advance space science and exploration. The organization is supported by individuals across the world, and does not accept government grants nor does it have major aerospace donations.
|
|
319
353
|
|
|
320
354
|
Please consider supporting our work by [becoming a member](https://www.planetary.org/join).
|
|
321
355
|
|
|
@@ -278,6 +278,39 @@ logging.basicConfig(
|
|
|
278
278
|
|
|
279
279
|
USASpending Python Wrapper is under active development. The API is stabilizing but may change as we refine the abstractions based on real-world usage. We welcome feedback on the interface design and feature priorities.
|
|
280
280
|
|
|
281
|
+
## Testing
|
|
282
|
+
|
|
283
|
+
The library includes both unit tests and integration tests.
|
|
284
|
+
|
|
285
|
+
### Running Unit Tests
|
|
286
|
+
|
|
287
|
+
Unit tests run against mocked API responses and do not require network access:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# Run all unit tests (default, excludes integration tests)
|
|
291
|
+
pytest
|
|
292
|
+
|
|
293
|
+
# Run with verbose output
|
|
294
|
+
pytest -v
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Running Integration Tests
|
|
298
|
+
|
|
299
|
+
Integration tests hit the real USASpending.gov API to verify end-to-end functionality. These are **excluded by default** to avoid network dependencies during normal development.
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Run only integration tests
|
|
303
|
+
pytest -m integration
|
|
304
|
+
|
|
305
|
+
# Run integration tests with verbose output
|
|
306
|
+
pytest -m integration -v
|
|
307
|
+
|
|
308
|
+
# Run all tests including integration
|
|
309
|
+
pytest -m ""
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Integration tests verify connectivity and response structure for all major resources including awards, recipients, agencies, spending, and award-related data (transactions, funding, subawards).
|
|
313
|
+
|
|
281
314
|
## Contributing
|
|
282
315
|
|
|
283
316
|
We welcome contributions to improve and expand the implementation and functionality.
|
|
@@ -288,7 +321,7 @@ This library was initially developed to serve the needs of The Planetary Society
|
|
|
288
321
|
|
|
289
322
|
We have open-sourced the project to enable others to better use USASpending data.
|
|
290
323
|
|
|
291
|
-
[The Planetary Society](planetary.org) is an independent nonprofit organization that empowers the world's citizens to advance space science and exploration. The organization is supported by individuals across the world, and does not accept government grants nor does it have major aerospace donations.
|
|
324
|
+
[The Planetary Society](https://planetary.org) is an independent nonprofit organization that empowers the world's citizens to advance space science and exploration. The organization is supported by individuals across the world, and does not accept government grants nor does it have major aerospace donations.
|
|
292
325
|
|
|
293
326
|
Please consider supporting our work by [becoming a member](https://www.planetary.org/join).
|
|
294
327
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "usaspending-orm"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.0"
|
|
4
4
|
description = "A Python ORM wrapper for the USAspending.gov API with intuitive queries, automatic pagination, and smart caching"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "Casey Dreier", email = "casey.dreier@planetary.org"}
|
|
@@ -50,4 +50,8 @@ requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
|
50
50
|
build-backend = "poetry.core.masonry.api"
|
|
51
51
|
|
|
52
52
|
[tool.pytest.ini_options]
|
|
53
|
-
pythonpath = "src"
|
|
53
|
+
pythonpath = "src"
|
|
54
|
+
markers = [
|
|
55
|
+
"integration: marks tests as integration tests (hit real USASpending API, run with: pytest -m integration)",
|
|
56
|
+
]
|
|
57
|
+
addopts = "-m 'not integration'"
|
|
@@ -17,7 +17,7 @@ class _Config:
|
|
|
17
17
|
def __init__(self):
|
|
18
18
|
# Default settings are defined here as instance attributes
|
|
19
19
|
self.base_url: str = "https://api.usaspending.gov/api/v2/"
|
|
20
|
-
self.user_agent: str = "usaspending-orm-python/0.
|
|
20
|
+
self.user_agent: str = "usaspending-orm-python/0.7.0"
|
|
21
21
|
self.timeout: int = 30
|
|
22
22
|
self.max_retries: int = 3
|
|
23
23
|
self.retry_delay: float = 10.0
|
|
@@ -65,9 +65,9 @@ class Agency(LazyRecord):
|
|
|
65
65
|
"""Initialize Agency instance.
|
|
66
66
|
|
|
67
67
|
Args:
|
|
68
|
-
data: Toptier agency data merged with top-level agency fields
|
|
69
|
-
client: USASpendingClient client instance
|
|
70
|
-
subtier_data: Optional subtier agency data for subtier_agency property
|
|
68
|
+
data: Toptier agency data merged with top-level agency fields.
|
|
69
|
+
client: USASpendingClient client instance.
|
|
70
|
+
subtier_data: Optional subtier agency data for subtier_agency property.
|
|
71
71
|
"""
|
|
72
72
|
# Use the base validation method (dict-only)
|
|
73
73
|
raw = self.validate_init_data(data, "Agency", allow_string_id=False)
|
|
@@ -81,7 +81,7 @@ class Agency(LazyRecord):
|
|
|
81
81
|
|
|
82
82
|
Returns:
|
|
83
83
|
Optional[Dict[str, Any]]: Full agency data from the API, or None
|
|
84
|
-
|
|
84
|
+
if unable to fetch due to missing toptier_code or API error.
|
|
85
85
|
"""
|
|
86
86
|
# Try to get toptier_code from existing data
|
|
87
87
|
toptier_code = None
|
|
@@ -115,17 +115,17 @@ class Agency(LazyRecord):
|
|
|
115
115
|
"""Fetch award summary data for a given agency code.
|
|
116
116
|
|
|
117
117
|
Args:
|
|
118
|
-
award_type_codes
|
|
119
|
-
|
|
120
|
-
fiscal_year
|
|
121
|
-
|
|
122
|
-
agency_type
|
|
123
|
-
|
|
118
|
+
award_type_codes: Optional list of award type codes to filter by.
|
|
119
|
+
If None, includes all award types.
|
|
120
|
+
fiscal_year: Fiscal year to filter by. If None, defaults to the
|
|
121
|
+
current fiscal year.
|
|
122
|
+
agency_type: Type of agency relationship to filter by. Must be
|
|
123
|
+
"awarding" or "funding". Defaults to "awarding".
|
|
124
124
|
|
|
125
125
|
Returns:
|
|
126
126
|
Optional[Dict[str, Any]]: Award summary data dictionary containing
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
obligations, transaction counts, and other summary metrics, or
|
|
128
|
+
None if unable to fetch due to missing agency code or API error.
|
|
129
129
|
"""
|
|
130
130
|
# Get toptier code
|
|
131
131
|
toptier_code = self.code
|
|
@@ -155,8 +155,7 @@ class Agency(LazyRecord):
|
|
|
155
155
|
"""Fiscal year for the agency data.
|
|
156
156
|
|
|
157
157
|
Returns:
|
|
158
|
-
Optional[int]: The fiscal year for this agency's data,
|
|
159
|
-
or None if not available.
|
|
158
|
+
Optional[int]: The fiscal year for this agency's data, or None.
|
|
160
159
|
"""
|
|
161
160
|
fiscal_year = self._lazy_get("fiscal_year")
|
|
162
161
|
return to_int(fiscal_year)
|
|
@@ -169,7 +168,7 @@ class Agency(LazyRecord):
|
|
|
169
168
|
the agency at the top-tier level in the government hierarchy.
|
|
170
169
|
|
|
171
170
|
Returns:
|
|
172
|
-
Optional[str]: The toptier agency code, or None
|
|
171
|
+
Optional[str]: The toptier agency code, or None.
|
|
173
172
|
"""
|
|
174
173
|
return self._lazy_get("toptier_code", "code")
|
|
175
174
|
|
|
@@ -178,7 +177,7 @@ class Agency(LazyRecord):
|
|
|
178
177
|
"""Alias for toptier_code property.
|
|
179
178
|
|
|
180
179
|
Returns:
|
|
181
|
-
Optional[str]: The toptier agency code, or None
|
|
180
|
+
Optional[str]: The toptier agency code, or None.
|
|
182
181
|
"""
|
|
183
182
|
return self.toptier_code
|
|
184
183
|
|
|
@@ -187,8 +186,7 @@ class Agency(LazyRecord):
|
|
|
187
186
|
"""Primary agency name.
|
|
188
187
|
|
|
189
188
|
Returns:
|
|
190
|
-
Optional[str]: The official name of the agency,
|
|
191
|
-
or None if not available.
|
|
189
|
+
Optional[str]: The official name of the agency, or None.
|
|
192
190
|
"""
|
|
193
191
|
# Agency now contains toptier data directly
|
|
194
192
|
return self._lazy_get("name")
|
|
@@ -198,8 +196,7 @@ class Agency(LazyRecord):
|
|
|
198
196
|
"""Primary agency abbreviation.
|
|
199
197
|
|
|
200
198
|
Returns:
|
|
201
|
-
Optional[str]: The official abbreviation of the agency,
|
|
202
|
-
or None if not available.
|
|
199
|
+
Optional[str]: The official abbreviation of the agency, or None.
|
|
203
200
|
"""
|
|
204
201
|
# Agency now contains toptier data directly
|
|
205
202
|
return self._lazy_get("abbreviation")
|
|
@@ -209,8 +206,7 @@ class Agency(LazyRecord):
|
|
|
209
206
|
"""Internal identifier from USASpending.gov.
|
|
210
207
|
|
|
211
208
|
Returns:
|
|
212
|
-
Optional[int]: The internal agency identifier,
|
|
213
|
-
or None if not available.
|
|
209
|
+
Optional[int]: The internal agency identifier, or None.
|
|
214
210
|
"""
|
|
215
211
|
return self.agency_id
|
|
216
212
|
|
|
@@ -219,8 +215,7 @@ class Agency(LazyRecord):
|
|
|
219
215
|
"""Internal identifier from USASpending.gov.
|
|
220
216
|
|
|
221
217
|
Returns:
|
|
222
|
-
Optional[int]: The internal agency identifier used by the API,
|
|
223
|
-
or None if not available.
|
|
218
|
+
Optional[int]: The internal agency identifier used by the API, or None.
|
|
224
219
|
"""
|
|
225
220
|
agency_id = self._lazy_get("agency_id", "id")
|
|
226
221
|
return to_int(agency_id)
|
|
@@ -230,8 +225,7 @@ class Agency(LazyRecord):
|
|
|
230
225
|
"""Filename of the agency's icon/logo.
|
|
231
226
|
|
|
232
227
|
Returns:
|
|
233
|
-
Optional[str]: The filename of the agency's icon or logo image,
|
|
234
|
-
or None if not available.
|
|
228
|
+
Optional[str]: The filename of the agency's icon or logo image, or None.
|
|
235
229
|
"""
|
|
236
230
|
return self._lazy_get("icon_filename")
|
|
237
231
|
|
|
@@ -240,8 +234,7 @@ class Agency(LazyRecord):
|
|
|
240
234
|
"""Agency mission statement.
|
|
241
235
|
|
|
242
236
|
Returns:
|
|
243
|
-
Optional[str]: The official mission statement of the agency,
|
|
244
|
-
or None if not available.
|
|
237
|
+
Optional[str]: The official mission statement of the agency, or None.
|
|
245
238
|
"""
|
|
246
239
|
return self._lazy_get("mission")
|
|
247
240
|
|
|
@@ -250,8 +243,7 @@ class Agency(LazyRecord):
|
|
|
250
243
|
"""Agency website URL.
|
|
251
244
|
|
|
252
245
|
Returns:
|
|
253
|
-
Optional[str]: The official website URL of the agency,
|
|
254
|
-
or None if not available.
|
|
246
|
+
Optional[str]: The official website URL of the agency, or None.
|
|
255
247
|
"""
|
|
256
248
|
return self._lazy_get("website")
|
|
257
249
|
|
|
@@ -260,8 +252,7 @@ class Agency(LazyRecord):
|
|
|
260
252
|
"""URL to the agency's congressional justification.
|
|
261
253
|
|
|
262
254
|
Returns:
|
|
263
|
-
Optional[str]: The URL to the agency's congressional justification document,
|
|
264
|
-
or None if not available.
|
|
255
|
+
Optional[str]: The URL to the agency's congressional justification document, or None.
|
|
265
256
|
"""
|
|
266
257
|
return self._lazy_get("congressional_justification_url")
|
|
267
258
|
|
|
@@ -271,7 +262,7 @@ class Agency(LazyRecord):
|
|
|
271
262
|
|
|
272
263
|
Returns:
|
|
273
264
|
Optional[str]: Descriptive text about the agency's data quality,
|
|
274
|
-
|
|
265
|
+
coverage, or other relevant information, or None.
|
|
275
266
|
"""
|
|
276
267
|
return self._lazy_get("about_agency_data")
|
|
277
268
|
|
|
@@ -281,7 +272,7 @@ class Agency(LazyRecord):
|
|
|
281
272
|
|
|
282
273
|
Returns:
|
|
283
274
|
Optional[int]: The total count of subtier agencies that report
|
|
284
|
-
|
|
275
|
+
to this toptier agency, or None.
|
|
285
276
|
"""
|
|
286
277
|
count = self._lazy_get("subtier_agency_count")
|
|
287
278
|
return to_int(count)
|
|
@@ -292,7 +283,7 @@ class Agency(LazyRecord):
|
|
|
292
283
|
|
|
293
284
|
Returns:
|
|
294
285
|
List[str]: List of informational messages from the API
|
|
295
|
-
|
|
286
|
+
related to this agency's data. Empty list if no messages.
|
|
296
287
|
"""
|
|
297
288
|
messages = self._lazy_get("messages", default=[])
|
|
298
289
|
if not isinstance(messages, list):
|
|
@@ -305,8 +296,8 @@ class Agency(LazyRecord):
|
|
|
305
296
|
|
|
306
297
|
Returns:
|
|
307
298
|
List[DefCode]: List of DefCode dataclass instances containing
|
|
308
|
-
|
|
309
|
-
|
|
299
|
+
disaster emergency fund codes associated with this agency.
|
|
300
|
+
Empty list if no DEFCs are available.
|
|
310
301
|
"""
|
|
311
302
|
def_codes_data = self._lazy_get("def_codes", default=[])
|
|
312
303
|
if not isinstance(def_codes_data, list):
|
|
@@ -344,7 +335,7 @@ class Agency(LazyRecord):
|
|
|
344
335
|
|
|
345
336
|
Returns:
|
|
346
337
|
bool: True if the agency has a dedicated profile page on USASpending.gov,
|
|
347
|
-
|
|
338
|
+
False otherwise.
|
|
348
339
|
"""
|
|
349
340
|
return bool(self.get_value(["has_agency_page"], default=False))
|
|
350
341
|
|
|
@@ -354,7 +345,7 @@ class Agency(LazyRecord):
|
|
|
354
345
|
|
|
355
346
|
Returns:
|
|
356
347
|
Optional[str]: The name of a specific office or division within
|
|
357
|
-
|
|
348
|
+
the agency, or None.
|
|
358
349
|
"""
|
|
359
350
|
return self.get_value("office_agency_name")
|
|
360
351
|
|
|
@@ -364,7 +355,7 @@ class Agency(LazyRecord):
|
|
|
364
355
|
|
|
365
356
|
Returns:
|
|
366
357
|
Optional[str]: The URL-friendly slug identifier used in
|
|
367
|
-
|
|
358
|
+
USASpending.gov URLs for this agency, or None.
|
|
368
359
|
"""
|
|
369
360
|
return self.get_value("slug")
|
|
370
361
|
|
|
@@ -374,7 +365,7 @@ class Agency(LazyRecord):
|
|
|
374
365
|
|
|
375
366
|
Returns:
|
|
376
367
|
Optional[Decimal]: The current fiscal year's total obligations
|
|
377
|
-
|
|
368
|
+
for this agency, or None.
|
|
378
369
|
"""
|
|
379
370
|
return self.total_obligations
|
|
380
371
|
|
|
@@ -389,7 +380,7 @@ class Agency(LazyRecord):
|
|
|
389
380
|
|
|
390
381
|
Returns:
|
|
391
382
|
Optional[Decimal]: The total dollar amount of obligations
|
|
392
|
-
|
|
383
|
+
for the current fiscal year, or None.
|
|
393
384
|
"""
|
|
394
385
|
obligations = self.get_value(["total_obligations", "obligations"])
|
|
395
386
|
if not obligations:
|
|
@@ -403,7 +394,7 @@ class Agency(LazyRecord):
|
|
|
403
394
|
|
|
404
395
|
Returns:
|
|
405
396
|
Optional[date]: The date of the most recent award action
|
|
406
|
-
|
|
397
|
+
associated with this agency, or None.
|
|
407
398
|
"""
|
|
408
399
|
|
|
409
400
|
# Check if value is present already (often provided in search results)
|
|
@@ -422,7 +413,7 @@ class Agency(LazyRecord):
|
|
|
422
413
|
|
|
423
414
|
Returns:
|
|
424
415
|
Optional[int]: The total number of transactions associated
|
|
425
|
-
|
|
416
|
+
with all awards for this agency, or None.
|
|
426
417
|
"""
|
|
427
418
|
|
|
428
419
|
# Check if value is present already (often provided in search results)
|
|
@@ -440,8 +431,8 @@ class Agency(LazyRecord):
|
|
|
440
431
|
|
|
441
432
|
Returns:
|
|
442
433
|
AwardsSearch: A query builder instance pre-filtered to show awards
|
|
443
|
-
|
|
444
|
-
|
|
434
|
+
where this agency is the top-tier awarding agency. Use this to
|
|
435
|
+
search and filter awards associated with this agency.
|
|
445
436
|
"""
|
|
446
437
|
return self._client.awards.search().agency(self.name, "awarding", "toptier")
|
|
447
438
|
|
|
@@ -451,9 +442,9 @@ class Agency(LazyRecord):
|
|
|
451
442
|
|
|
452
443
|
Returns:
|
|
453
444
|
List[SubTierAgency]: List of SubTierAgency model instances
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
445
|
+
representing all subtier agencies that report to this
|
|
446
|
+
toptier agency. Returns empty list if no subagencies
|
|
447
|
+
are found or if there's an API error.
|
|
457
448
|
"""
|
|
458
449
|
# Get toptier code
|
|
459
450
|
toptier_code = self.code
|
|
@@ -499,16 +490,16 @@ class Agency(LazyRecord):
|
|
|
499
490
|
"""Get obligations for this agency, optionally filtered.
|
|
500
491
|
|
|
501
492
|
Args:
|
|
502
|
-
fiscal_year
|
|
503
|
-
|
|
504
|
-
agency_type
|
|
505
|
-
|
|
506
|
-
award_type_codes
|
|
507
|
-
|
|
493
|
+
fiscal_year: Fiscal year to filter by. If None, defaults to the
|
|
494
|
+
current fiscal year.
|
|
495
|
+
agency_type: Type of agency relationship to filter by. Must be
|
|
496
|
+
"awarding" or "funding". Defaults to "awarding".
|
|
497
|
+
award_type_codes: Optional list of award type codes to filter by.
|
|
498
|
+
If None, includes all award types.
|
|
508
499
|
|
|
509
500
|
Returns:
|
|
510
501
|
Optional[float]: Total obligations amount as a float,
|
|
511
|
-
|
|
502
|
+
or None if unavailable due to missing data or API error.
|
|
512
503
|
"""
|
|
513
504
|
|
|
514
505
|
# Fetch from award summary API
|
|
@@ -525,7 +516,7 @@ class Agency(LazyRecord):
|
|
|
525
516
|
|
|
526
517
|
Returns:
|
|
527
518
|
Optional[Decimal]: The total dollar amount of contract obligations
|
|
528
|
-
|
|
519
|
+
for this agency, or None if unavailable.
|
|
529
520
|
"""
|
|
530
521
|
summary = self._get_award_summary(award_type_codes=list(CONTRACT_CODES))
|
|
531
522
|
return to_decimal(summary.get("obligations")) if summary else None
|
|
@@ -536,7 +527,7 @@ class Agency(LazyRecord):
|
|
|
536
527
|
|
|
537
528
|
Returns:
|
|
538
529
|
Optional[Decimal]: The total dollar amount of grant obligations
|
|
539
|
-
|
|
530
|
+
for this agency, or None if unavailable.
|
|
540
531
|
"""
|
|
541
532
|
summary = self._get_award_summary(award_type_codes=list(GRANT_CODES))
|
|
542
533
|
return to_decimal(summary.get("obligations")) if summary else None
|
|
@@ -547,7 +538,7 @@ class Agency(LazyRecord):
|
|
|
547
538
|
|
|
548
539
|
Returns:
|
|
549
540
|
Optional[Decimal]: The total dollar amount of IDV obligations
|
|
550
|
-
|
|
541
|
+
for this agency in the current fiscal year, or None if unavailable.
|
|
551
542
|
"""
|
|
552
543
|
summary = self._get_award_summary(award_type_codes=list(IDV_CODES))
|
|
553
544
|
return to_decimal(summary.get("obligations")) if summary else None
|
|
@@ -558,7 +549,7 @@ class Agency(LazyRecord):
|
|
|
558
549
|
|
|
559
550
|
Returns:
|
|
560
551
|
Optional[Decimal]: The total dollar amount of loan obligations
|
|
561
|
-
|
|
552
|
+
for this agency, or None if unavailable.
|
|
562
553
|
"""
|
|
563
554
|
summary = self._get_award_summary(award_type_codes=list(LOAN_CODES))
|
|
564
555
|
return to_decimal(summary.get("obligations")) if summary else None
|
|
@@ -569,7 +560,7 @@ class Agency(LazyRecord):
|
|
|
569
560
|
|
|
570
561
|
Returns:
|
|
571
562
|
Optional[Decimal]: The total dollar amount of direct payment obligations
|
|
572
|
-
|
|
563
|
+
for this agency, or None if unavailable.
|
|
573
564
|
"""
|
|
574
565
|
summary = self._get_award_summary(award_type_codes=list(DIRECT_PAYMENT_CODES))
|
|
575
566
|
return to_decimal(summary.get("obligations")) if summary else None
|
|
@@ -580,7 +571,7 @@ class Agency(LazyRecord):
|
|
|
580
571
|
|
|
581
572
|
Returns:
|
|
582
573
|
Optional[Decimal]: The total dollar amount of other assistance obligations
|
|
583
|
-
|
|
574
|
+
for this agency, or None if unavailable.
|
|
584
575
|
"""
|
|
585
576
|
summary = self._get_award_summary(award_type_codes=list(OTHER_CODES))
|
|
586
577
|
return to_decimal(summary.get("obligations")) if summary else None
|
|
@@ -594,16 +585,16 @@ class Agency(LazyRecord):
|
|
|
594
585
|
"""Get transaction count for this agency, optionally filtered.
|
|
595
586
|
|
|
596
587
|
Args:
|
|
597
|
-
fiscal_year
|
|
598
|
-
|
|
599
|
-
agency_type
|
|
600
|
-
|
|
601
|
-
award_type_codes
|
|
602
|
-
|
|
588
|
+
fiscal_year: Fiscal year to filter by. If None, uses the agency's
|
|
589
|
+
fiscal year or current fiscal year.
|
|
590
|
+
agency_type: Type of agency relationship to filter by. Must be
|
|
591
|
+
"awarding" or "funding". Defaults to "awarding".
|
|
592
|
+
award_type_codes: Optional list of award type codes to filter by.
|
|
593
|
+
If None, includes all award types.
|
|
603
594
|
|
|
604
595
|
Returns:
|
|
605
596
|
Optional[int]: Total transaction count as an integer,
|
|
606
|
-
|
|
597
|
+
or None if unavailable due to missing data or API error.
|
|
607
598
|
"""
|
|
608
599
|
# If no filters and we have existing data, return it
|
|
609
600
|
if not any([fiscal_year, award_type_codes]) and agency_type == "awarding":
|
|
@@ -624,7 +615,7 @@ class Agency(LazyRecord):
|
|
|
624
615
|
|
|
625
616
|
Returns:
|
|
626
617
|
str: A string representation showing the agency code and name
|
|
627
|
-
|
|
618
|
+
in the format "<Agency CODE: NAME>".
|
|
628
619
|
"""
|
|
629
620
|
name = self.name or "?"
|
|
630
621
|
code = self.code or "?"
|