OA Actions Example

  1"""Example usage of pyUSPTO for Office Action Text Retrieval.
  2
  3Demonstrates the OAActionsClient for searching full-text office action
  4documents, filtering by various criteria, inspecting section data,
  5and paginating through results.
  6"""
  7
  8import os
  9
 10from pyUSPTO import OAActionsClient, USPTOConfig
 11
 12# --- Client Initialization ---
 13api_key = os.environ.get("USPTO_API_KEY", "YOUR_API_KEY_HERE")
 14if api_key == "YOUR_API_KEY_HERE":
 15    raise ValueError("API key is not set. Set the USPTO_API_KEY environment variable.")
 16config = USPTOConfig(api_key=api_key)
 17client = OAActionsClient(config=config)
 18
 19print("-" * 40)
 20print("Example 1: Search by application number")
 21print("-" * 40)
 22
 23response = client.search(patent_application_number_q="11363598")
 24print(f"Found {response.num_found} office actions for application 11363598.")
 25for record in response.docs[:3]:
 26    print(f"\n  Doc Code: {record.legacy_document_code_identifier}")
 27    print(f"  Submission Date: {record.submission_date}")
 28    print(f"  Art Unit: {record.group_art_unit_number}")
 29    if record.section:
 30        if record.section.section_102_rejection_text:
 31            print("  Has § 102 rejection text.")
 32        if record.section.section_103_rejection_text:
 33            print("  Has § 103 rejection text.")
 34
 35print("-" * 40)
 36print("Example 2: Search by document code (CTNF) and tech center")
 37print("-" * 40)
 38
 39response = client.search(
 40    tech_center_q="2800",
 41    legacy_document_code_identifier_q="CTNF",
 42    rows=5,
 43)
 44print(f"Found {response.num_found} CTNF office actions in tech center 2800.")
 45for record in response.docs:
 46    print(
 47        f"  App {record.patent_application_number}: "
 48        f"AU {record.group_art_unit_number}, "
 49        f"submitted {record.submission_date}"
 50    )
 51
 52print("-" * 40)
 53print("Example 3: Search by submission date range")
 54print("-" * 40)
 55
 56response = client.search(
 57    submission_date_from_q="2010-01-01",
 58    submission_date_to_q="2010-12-31",
 59    rows=5,
 60)
 61print(f"Found {response.num_found} office actions submitted in 2010.")
 62
 63print("-" * 40)
 64print("Example 4: Search with sort")
 65print("-" * 40)
 66
 67response = client.search(
 68    tech_center_q="1700",
 69    sort="submissionDate desc",
 70    rows=5,
 71)
 72print(f"Found {response.num_found} office actions in tech center 1700 (newest first).")
 73for record in response.docs:
 74    print(f"  {record.submission_date}: {record.invention_title}")
 75
 76print("-" * 40)
 77print("Example 5: Inspect section data")
 78print("-" * 40)
 79
 80response = client.search(
 81    criteria='id:"9c27199b54dc83c9a6f643b828990d0322071461557b31ead3428885"',
 82    rows=1,
 83)
 84if response.docs:
 85    record = response.docs[0]
 86    print(f"Record: {record.id}")
 87    print(f"  Patent Number: {record.patent_number}")
 88    print(f"  Invention Title: {record.invention_title}")
 89    if record.section:
 90        print("  Section 102 text (first 200 chars):")
 91        for text in record.section.section_102_rejection_text:
 92            if text:
 93                print(f"    {text[:200]}...")
 94
 95print("-" * 40)
 96print("Example 6: Paginate through results")
 97print("-" * 40)
 98
 99max_items = 30
100count = 0
101for _ in client.paginate(tech_center_q="1700", rows=10):
102    count += 1
103    if count >= max_items:
104        print(f"  ... (stopping at {max_items} items)")
105        break
106
107print(f"Retrieved {count} office action records via pagination.")
108
109print("-" * 40)
110print("Example 7: Get available fields")
111print("-" * 40)
112
113fields_response = client.get_fields()
114print(f"API Status: {fields_response.api_status}")
115print(f"Field Count: {fields_response.field_count}")
116print(f"Last Updated: {fields_response.last_data_updated_date}")
117print(f"Sample fields: {fields_response.fields[:5]}")