1"""Example usage of pyUSPTO for Office Action Citations.
2
3Demonstrates the OACitationsClient for searching citation data from
4Office Actions, filtering by various criteria, and paginating through results.
5"""
6
7import os
8
9from pyUSPTO import OACitationsClient, USPTOConfig
10
11# --- Client Initialization ---
12api_key = os.environ.get("USPTO_API_KEY", "YOUR_API_KEY_HERE")
13if api_key == "YOUR_API_KEY_HERE":
14 raise ValueError("API key is not set. Set the USPTO_API_KEY environment variable.")
15config = USPTOConfig(api_key=api_key)
16client = OACitationsClient(config=config)
17
18print("-" * 40)
19print("Example 1: Search by application number")
20print("-" * 40)
21
22response = client.search(patent_application_number_q="17519936")
23print(f"Found {response.num_found} citations for application 17519936.")
24for record in response.docs[:3]:
25 print(f"\n Legal Section: {record.legal_section_code}")
26 print(f" Action Type: {record.action_type_category}")
27 print(f" Reference: {record.reference_identifier}")
28 print(f" Examiner Cited: {record.examiner_cited_reference_indicator}")
29
30print("-" * 40)
31print("Example 2: Search by legal section code and tech center")
32print("-" * 40)
33
34response = client.search(
35 tech_center_q="2800",
36 legal_section_code_q="103",
37 rows=5,
38)
39print(f"Found {response.num_found} section 103 citations in tech center 2800.")
40for record in response.docs:
41 print(
42 f" App {record.patent_application_number}: "
43 f"AU {record.group_art_unit_number}, "
44 f"ref {record.parsed_reference_identifier}"
45 )
46
47print("-" * 40)
48print("Example 3: Search by examiner-cited indicator")
49print("-" * 40)
50
51response = client.search(
52 examiner_cited_reference_indicator_q=True,
53 tech_center_q="1700",
54 rows=5,
55)
56print(f"Found {response.num_found} examiner-cited references in tech center 1700.")
57for record in response.docs:
58 print(f" {record.reference_identifier}")
59
60print("-" * 40)
61print("Example 4: Search by create date range")
62print("-" * 40)
63
64response = client.search(
65 create_date_time_from_q="2025-07-01",
66 create_date_time_to_q="2025-07-04",
67 rows=5,
68)
69print(f"Found {response.num_found} citations created 2025-07-01 to 2025-07-04.")
70
71print("-" * 40)
72print("Example 5: Search with sort")
73print("-" * 40)
74
75response = client.search(
76 tech_center_q="2800",
77 sort="createDateTime desc",
78 rows=5,
79)
80print(f"Found {response.num_found} citations in tech center 2800 (newest first).")
81for record in response.docs:
82 print(f" {record.create_date_time}: {record.patent_application_number}")
83
84print("-" * 40)
85print("Example 6: Paginate through results")
86print("-" * 40)
87
88max_items = 30
89count = 0
90for _ in client.paginate(tech_center_q="2800", rows=10):
91 count += 1
92 if count >= max_items:
93 print(f" ... (stopping at {max_items} items)")
94 break
95
96print(f"Retrieved {count} citation records via pagination.")
97
98print("-" * 40)
99print("Example 7: Get available fields")
100print("-" * 40)
101
102fields_response = client.get_fields()
103print(f"API Status: {fields_response.api_status}")
104print(f"Field Count: {fields_response.field_count}")
105print(f"Last Updated: {fields_response.last_data_updated_date}")
106print(f"Sample fields: {fields_response.fields[:5]}")