ADAMSNRC API Client
This code was created by ChatGPT and Cursor. On ChatGPT the pdf with the API documentation was uploaded and simple prompt sent: "create simple python code to interface each endpoint on adams library api".
With the code generated I switched to Cursor, set model to Any and started vibe coding.
The result after many interactions and minor code edits is this package.
A robust Python client for the Nuclear Regulatory Commission's ADAMS (Agencywide Documents Access and Management System) API.
Author
Name: Max Oliver, CTO 3Flux.com
Features
- Type Safety: Full type hints for better IDE support and code clarity
- Error Handling: Comprehensive exception handling with custom error types
- Input Validation: Robust validation of all input parameters
- Retry Logic: Automatic retry mechanism for network requests
- Logging: Configurable logging for debugging and monitoring
- Configuration: Environment-based configuration management
- Utilities: Helper functions for data processing and validation
- Testing: Comprehensive test suite
Installation
pip install -r requirements.txt
Quick Start
from adamsnrc.main import content_search, advanced_search
# Simple content search
result = content_search(
properties_search=[("DocumentType", "ends", "NUREG")],
single_content_search="steam generator",
sort="DocumentDate",
order="DESC"
)
print(f"Found {result.count} documents")
for doc in result.results:
print(f"- {doc.get('title', 'No title')}")
# Advanced search with date range
from datetime import datetime
from adamsnrc.utils import build_date_range
date_range = build_date_range(
"01/01/2023 12:00 AM",
"12/31/2023 11:59 PM"
)
result = advanced_search(
properties_search_all=[("AuthorName", "starts", "Macfarlane")],
date_range=date_range,
sort="$title",
order="ASC"
)
Configuration
The client can be configured using environment variables:
# API Configuration
export ADAMS_BASE_URL="https://adams.nrc.gov/wba/services/search/advanced/nrc"
export ADAMS_TIMEOUT="60"
export ADAMS_MAX_RETRIES="3"
export ADAMS_RETRY_DELAY="1.0"
# Logging Configuration
export ADAMS_LOG_LEVEL="INFO"
API Reference
Main Functions
content_search()
Content search in the public library.
def content_search(
properties_search: Optional[List[Tuple[str, str, Any]]] = None,
properties_search_any: Optional[List[Tuple[str, str, Any]]] = None,
single_content_search: str = "",
sort: str = "DocumentDate",
order: str = "DESC"
) -> SearchResult
advanced_search()
Advanced search with additional options.
def advanced_search(
properties_search_all: Optional[List[Tuple[str, str, Any]]] = None,
properties_search_any: Optional[List[Tuple[str, str, Any]]] = None,
public_library: bool = True,
legacy_library: bool = False,
added_today: bool = False,
added_this_month: bool = False,
within_folder_enable: bool = False,
within_folder_insubfolder: bool = False,
within_folder_path: str = "",
sort: str = "$title",
order: str = "ASC"
) -> SearchResult
part21_search_content()
Search for Part 21 correspondence using content search.
part21_search_advanced()
Search for Part 21 correspondence using advanced search.
operating_reactor_ir_search_content()
Search for operating reactor inspection reports using content search.
operating_reactor_ir_search_advanced()
Search for operating reactor inspection reports using advanced search.
Data Structures
SearchResult
Container for search results with metadata.
@dataclass
class SearchResult:
meta: Dict[str, str] # Metadata (count, matches, etc.)
results: List[Dict[str, str]] # List of document results
@property
def count(self) -> int: # Number of results as integer
@property
def matches(self) -> int: # Number of matches as integer
Exception Types
ADAMSError: Base exception for all ADAMS API errorsADAMSRequestError: Request-related errors (timeout, network issues)ADAMSValidationError: Input validation errorsADAMSParseError: XML parsing errors
Utility Functions
Date and Time Utilities
from adamsnrc.utils import build_date_range, validate_and_format_date
# Build date range
date_range = build_date_range("01/01/2023 12:00 AM", "12/31/2023 11:59 PM")
# Validate and format date
formatted_date = validate_and_format_date("01/15/2023 02:30 PM")
Text Processing
from adamsnrc.utils import escape_special_chars, normalize_whitespace, truncate_text
# Escape special characters
escaped = escape_special_chars("test (with) [special] {chars}")
# Normalize whitespace
normalized = normalize_whitespace(" multiple spaces ")
# Truncate text
truncated = truncate_text("Very long text...", max_length=50)
Result Processing
from adamsnrc.utils import (
extract_metadata_from_result,
filter_results_by_date,
group_results_by_field,
calculate_result_stats
)
# Extract metadata
metadata = extract_metadata_from_result(result_dict)
# Filter by date
filtered = filter_results_by_date(results, start_date, end_date)
# Group by field
grouped = group_results_by_field(results, "AuthorName")
# Calculate statistics
stats = calculate_result_stats(results)
Examples
Basic Search
from adamsnrc.main import content_search
# Search for NUREG documents about steam generators
result = content_search(
properties_search=[("DocumentType", "ends", "NUREG")],
single_content_search="steam generator",
sort="DocumentDate",
order="DESC"
)
print(f"Found {result.count} NUREG documents about steam generators")
Advanced Search with Date Range
from adamsnrc.main import advanced_search
from adamsnrc.utils import build_date_range
# Search for documents by a specific author in a date range
date_range = build_date_range("01/01/2023 12:00 AM", "12/31/2023 11:59 PM")
result = advanced_search(
properties_search_all=[
("AuthorName", "starts", "Macfarlane"),
("DocumentType", "starts", "Speech")
],
date_range=date_range,
sort="$title",
order="ASC"
)
Part 21 Search
from adamsnrc.main import part21_search_content
# Search for Part 21 correspondence about safety valves
result = part21_search_content(
extra_and=[("AuthorAffiliation", "infolder", "NRC/NRR")],
text="safety valve",
sort="$size",
order="DESC"
)
Result Processing
from adamsnrc.utils import calculate_result_stats, group_results_by_field
# Get search results
result = content_search(properties_search=[("DocumentType", "ends", "NUREG")])
# Calculate statistics
stats = calculate_result_stats(result.results)
print(f"Total results: {stats['total_results']}")
print(f"Unique authors: {stats['unique_authors']}")
print(f"Average file size: {stats['average_size']} bytes")
# Group by author
grouped = group_results_by_field(result.results, "AuthorName")
for author, docs in grouped.items():
print(f"{author}: {len(docs)} documents")
Error Handling
from adamsnrc.main import content_search, ADAMSError, ADAMSValidationError
try:
result = content_search(
properties_search=[("DocumentType", "ends", "NUREG")],
order="INVALID" # This will raise an error
)
except ADAMSValidationError as e:
print(f"Validation error: {e}")
except ADAMSError as e:
print(f"ADAMS API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Testing
Run the test suite:
python -m pytest adamsnrc/test_main.py -v
Or run specific test classes:
python -m pytest adamsnrc/test_main.py::TestSearchFunctions -v
Logging
The client uses Python's standard logging module. Configure logging level:
import logging
logging.getLogger('adamsnrc').setLevel(logging.DEBUG)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
Version 2.0.0 (Refactored)
- Added comprehensive type hints
- Implemented robust error handling with custom exceptions
- Added input validation for all parameters
- Implemented retry logic for network requests
- Added configuration management
- Created utility functions for data processing
- Added comprehensive test suite
- Improved documentation and examples
- Added logging support
- Made the code more maintainable and robust
Metadata
Release files for adamsnrc 2.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adamsnrc-2.0.14.tar.gz | 52.5 kB | Without provenance | Details for adamsnrc-2.0.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adamsnrc-2.0.14-py3-none-any.whl | Python 3 | none | any | Details for adamsnrc-2.0.14-py3-none-any.whl |
Total release size: 106.4 kB
Release files / adamsnrc-2.0.14.tar.gz
| Download URL | adamsnrc-2.0.14.tar.gz |
|---|---|
| Size | 52.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
443ac9f5583404920005ac9511c5127e9b18f56ac906a1af56147acd234279dd
|
|
BLAKE2b-256 checksum How to use checksums |
1b7a369cc4c2184eebe7fee86fe11c5da12215da5ae3af7c1c827277c0e7e410
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / adamsnrc-2.0.14-py3-none-any.whl
| Download URL | adamsnrc-2.0.14-py3-none-any.whl |
|---|---|
| Size | 53.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a83b12e7a3f4cdee1dce6f96d5131d8b9bb4dde3bd06b8c4133bd7b35da6683
|
|
BLAKE2b-256 checksum How to use checksums |
8e191903162efcfc83b76f5ffddcd698d6466c6efe72e06eabf2408a319d3526
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for adamsnrc 2.0.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.