Skip to content

Quick Start Guide

Basic Usage

Initialize the Client

from njleg_api import APIClient

# Basic initialization
client = APIClient()

# With API key and custom settings
client = APIClient(
    api_key="your_api_key_here",
    requests_per_minute=100,
    timeout=30.0
)

Working with Bills

# Get bill details
bill_endpoint = client.get_bill_detail("A1234", session=2024)

# Fetch bill description
description = bill_endpoint.get_bill_description()
print(f"Synopsis: {description.synopsis}")

# Get bill sponsors
sponsors = bill_endpoint.get_bill_sponsors()
for sponsor in sponsors:
    print(f"{sponsor.full_name}: {sponsor.sponsor_description}")

# Get bill history
history = bill_endpoint.get_bill_history()
for action in history:
    print(f"{action.action_date}: {action.action_description}")

Working with Committees

# Get committee information
committee_endpoint = client.get_committee_info()

# Fetch all Assembly committees
assembly = committee_endpoint.get_assembly_committees()
for committee in assembly.committee_info:
    print(f"{committee.code_description}")

# Get committee members
for member in assembly.committee_members[:5]:
    if member.is_chair:
        print(f"Chair: {member.full_name}")

Working with Legislators

# Get legislator data
legislator_endpoint = client.get_legislator_data()

# Fetch all current legislators
legislators = legislator_endpoint.get_current_legislators()
for leg in legislators:
    print(f"{leg.full_name} - District {leg.district}")

# Search for a specific legislator
try:
    senator = legislator_endpoint.get_legislator_by_name("Smith", "John")
    print(f"Found: {senator.full_name}")
except LegislatorNotFoundError:
    print("Legislator not found")

Using Caching

from njleg_api import APIClient, CacheManager

# Set up caching
cache_manager = CacheManager(
    cache_dir="/path/to/cache",
    ttl_hours=24  # Cache for 24 hours
)

# Initialize client with caching
client = APIClient(cache_manager=cache_manager)

# First request hits API
data1 = client.get_legislator_data().get_all_legislators()

# Second request uses cache (fast!)
data2 = client.get_legislator_data().get_all_legislators()

# Clear expired cache entries
removed = cache_manager.clear_expired()
print(f"Removed {removed} expired cache files")

Working with Video/Media

# Get committee meeting videos
video_endpoint = client.get_video_retrieval(
    committee="ABUB",
    session=2024
)

# Get meeting data
meeting_data = video_endpoint.response
print(f"Committee: {meeting_data.committee.code_description}")
print(f"Chair: {meeting_data.leadership.chair_name}")

# Access agenda items
for item in meeting_data.agenda_items:
    print(f"{item.agenda_date}: {item.description_for_link}")
    if item.archive_name:
        print(f"  Archive: {item.archive_name}")

Error Handling

from njleg_api import APIClient
from httpx import HTTPError

client = APIClient()

try:
    # Attempt to fetch data
    bill = client.get_bill_detail("INVALID", 2024)
    data = bill.get_bill_description()
except HTTPError as e:
    print(f"HTTP error occurred: {e}")
except ValueError as e:
    print(f"Invalid data: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

CLI Usage

The package includes a CLI tool:

# Show version
njleg --version

# Set logging level
njleg --log-level DEBUG

# Run with custom log level
njleg --log-level INFO

Advanced Features

Custom Request Configuration

client = APIClient(
    base_url="https://custom.api.url/",
    timeout=60.0,  # 60 second timeout
    requests_per_minute=50  # Rate limiting
)

Logging Configuration

from njleg_api import set_global_log_level, get_logger
import logging

# Set global log level
set_global_log_level(logging.DEBUG)

# Get a logger for custom logging
logger = get_logger()
logger.info("Starting data fetch...")

Next Steps

  • Explore the API Reference for complete documentation
  • Review individual endpoint documentation for specific features
  • Check the project repository for examples