SDKs overview
The Federal Register provides a comprehensive API to access its public data programmatically. This includes published documents, details on federal agencies, and public inspection documents. The API follows a RESTful architecture, allowing developers to retrieve data using standard HTTP methods. While the Federal Register team offers an official Python SDK, the API is accessible via direct HTTP requests using any programming language capable of making web requests. This design choice means developers are not strictly limited to SDKs and can integrate the Federal Register data into diverse applications using tools like cURL, Node.js, Ruby, or PHP for direct API calls, as demonstrated in the official developer resources.
The developer experience is supported by detailed documentation that includes code examples in multiple languages, facilitating integration for a broad range of technical users. A key feature is that basic access to the Federal Register API does not require an API key, simplifying the initial setup and enabling immediate data retrieval. This open access aligns with the Federal Register's mission to provide public information. For more detailed information on the API's capabilities and available endpoints, refer to the Federal Register API reference.
Official SDKs by language
The Federal Register maintains an official SDK primarily for the Python programming language. This SDK is designed to encapsulate the complexities of direct API requests, providing a more idiomatic interface for Python developers to interact with Federal Register data. It handles URL construction, parameter serialization, and response parsing, streamlining the process of querying and consuming government data. The official documentation includes examples and guides specific to this SDK, ensuring developers can quickly integrate it into their Python projects.
The table below provides an overview of the officially supported SDK:
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | federal-register |
pip install federal-register |
Stable |
For detailed usage and examples of the Python SDK, developers should consult the Federal Register Developer Resources, which provides comprehensive guides and code snippets.
Installation
Installing the official Federal Register Python SDK is performed using pip, the standard package installer for Python. This method ensures that the SDK and its dependencies are correctly installed and ready for use in your development environment. Before installation, it is recommended to ensure you have a compatible version of Python and pip installed on your system. Python 3.6 or newer is generally recommended for modern Python package installations.
Prerequisites
- Python 3.6+
pip(usually included with Python installations)
Installation steps for Python SDK
-
Open your terminal or command prompt:
# On macOS/Linux open Terminal # On Windows open Command Prompt or PowerShell -
Install the SDK using pip:
pip install federal-registerIf you are working within a virtual environment, ensure it is activated before running the installation command. This practice helps manage project dependencies in isolation.
-
Verify installation (optional):
You can verify that the package was installed by trying to import it in a Python interpreter:
python -c "import federal_register; print('federal-register SDK installed successfully.')"If no errors are reported, the SDK has been successfully installed. For more general guidance on Python package management, the Python documentation on pip provides comprehensive details.
Quickstart example
This quickstart example demonstrates how to use the official Federal Register Python SDK to search for documents and retrieve basic information. This example will query for documents related to a specific topic and print out some details about the results. This script can be executed directly after installing the federal-register package.
import federal_register
def search_federal_register(query):
"""Searches the Federal Register for documents matching a query."""
client = federal_register.Client()
try:
# Perform a search for documents. The API does not require an API key for basic searches.
search_results = client.search_documents(conditions={ "term": query })
if search_results and search_results.get('results'):
print(f"Found {len(search_results['results'])} documents for '{query}':")
for doc in search_results['results']:
print(f" Title: {doc.get('title')}")
print(f" Document Number: {doc.get('document_number')}")
print(f" Publication Date: {doc.get('publication_date')}")
print(f" URL: {doc.get('html_url')}")
print("-" * 20)
else:
print(f"No documents found for '{query}'.")
except federal_register.exceptions.FederalRegisterException as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
search_term = "environmental protection agency"
search_federal_register(search_term)
How to run the example
-
Save the code: Save the code above into a file named
fr_quickstart.py. -
Run from your terminal: Navigate to the directory where you saved the file and execute it using Python:
python fr_quickstart.py
This script will connect to the Federal Register API, perform the search, and print the results to your console. You can modify the search_term variable to explore different topics or adapt the code to retrieve other types of data available through the API, such as specific agencies or public inspection documents, by consulting the Federal Register API documentation.
Community libraries
While the Federal Register provides an official Python SDK, its RESTful API design encourages direct integration using various programming languages and HTTP clients. This approach means that developers often create custom wrappers or utility functions tailored to their specific projects rather than relying on a single, broadly adopted community-contributed library. The API's straightforward access, which typically does not require an API key for public data, also reduces the barrier to entry for direct HTTP requests, making a dedicated community SDK less critical for integration.
Developers frequently use standard HTTP client libraries available in their preferred programming languages to interact with the Federal Register API. Examples include:
-
Python: The
requestslibrary is a common choice for making HTTP requests.import requests url = "https://www.federalregister.gov/api/v1/documents.json?conditions%5Bterm%5D=climate" response = requests.get(url) data = response.json() print(data) -
JavaScript/Node.js:
fetchAPI oraxiosfor making web requests.// Using Node.js with 'node-fetch' (install with: npm install node-fetch) const fetch = require('node-fetch'); async function getFederalRegisterData() { const url = 'https://www.federalregister.gov/api/v1/documents.json?conditions%5Bterm%5D=healthcare'; try { const response = await fetch(url); const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching Federal Register data:', error); } } getFederalRegisterData(); -
Ruby: The built-in
Net::HTTPlibrary orhttpartygem.require 'net/http' require 'json' uri = URI('https://www.federalregister.gov/api/v1/documents.json?conditions%5Bterm%5D=education') response = Net::HTTP.get(uri) data = JSON.parse(response) puts data
These examples illustrate how direct API interaction is often preferred and straightforward, reducing the perceived need for extensive third-party libraries. Developers looking to contribute to or find community-driven tools might explore public code repositories on platforms like GitHub, searching for projects that interact with the Federal Register API, though specific, widely-recognized community SDKs are not prominently featured.