1"""Example usage of pyUSPTO for Enriched Cited Reference Metadata.
2
3Demonstrates the EnrichedCitationsClient for searching citation data
4extracted from patent office actions, filtering by various criteria,
5and paginating through results.
6"""
7
8import os
9
10from pyUSPTO import EnrichedCitationsClient, 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 = EnrichedCitationsClient(config=config)
18
19print("-" * 40)
20print("Example 1: Search by application number")
21print("-" * 40)
22
23response = client.search_citations(patent_application_number_q="15061308")
24print(f"Found {response.num_found} citations for application 15061308.")
25for citation in response.docs[:5]:
26 print(f"\n Cited Document: {citation.cited_document_identifier}")
27 print(f" Category Code: {citation.citation_category_code}")
28 print(f" Office Action Date: {citation.office_action_date}")
29 print(f" Office Action Type: {citation.office_action_category}")
30 if citation.examiner_cited_reference_indicator:
31 print(" Cited by: Examiner")
32 if citation.passage_location_text:
33 print(f" Passages: {citation.passage_location_text}")
34
35print("-" * 40)
36print("Example 2: Search by tech center and citation category")
37print("-" * 40)
38
39response = client.search_citations(
40 tech_center_q="2800",
41 citation_category_code_q="X",
42 rows=5,
43)
44print(f"Found {response.num_found} 'X' citations in tech center 2800.")
45for citation in response.docs:
46 print(
47 f" App {citation.patent_application_number}: "
48 f"{citation.cited_document_identifier} "
49 f"(claims: {citation.related_claim_number_text})"
50 )
51
52print("-" * 40)
53print("Example 3: Search by date range")
54print("-" * 40)
55
56response = client.search_citations(
57 office_action_date_from_q="2019-01-01",
58 office_action_date_to_q="2019-12-31",
59 rows=5,
60)
61print(f"Found {response.num_found} citations from 2019.")
62
63print("-" * 40)
64print("Example 4: Combined filters")
65print("-" * 40)
66
67response = client.search_citations(
68 tech_center_q="2800",
69 citation_category_code_q="Y",
70 examiner_cited_q=True,
71 rows=5,
72)
73print(f"Found {response.num_found} examiner-cited 'Y' citations in tech center 2800.")
74for citation in response.docs:
75 print(
76 f" App {citation.patent_application_number}: "
77 f"{citation.cited_document_identifier} "
78 f"(art unit: {citation.group_art_unit_number})"
79 )
80
81print("-" * 40)
82print("Example 5: Search with sort")
83print("-" * 40)
84
85response = client.search_citations(
86 tech_center_q="2800",
87 sort="officeActionDate desc",
88 rows=5,
89)
90print(f"Found {response.num_found} citations, sorted by date descending.")
91for citation in response.docs:
92 print(f" {citation.office_action_date}: {citation.cited_document_identifier}")
93
94print("-" * 40)
95print("Example 6: Search by cited document identifier")
96print("-" * 40)
97
98response = client.search_citations(
99 cited_document_identifier_q="US 20190165601 A1",
100 rows=5,
101)
102print(f"Found {response.num_found} citations of US 20190165601 A1.")
103
104print("-" * 40)
105print("Example 7: Paginate through results")
106print("-" * 40)
107
108max_items = 30
109count = 0
110for citation in client.paginate_citations(tech_center_q="2800", rows=10):
111 print(
112 f" App {citation.patent_application_number}: {citation.cited_document_identifier}"
113 )
114 count += 1
115 if count >= max_items:
116 print(f" ... (stopping at {max_items} items)")
117 break
118
119print(f"Retrieved {count} citations via pagination")
120
121print("-" * 40)
122print("Example 8: Get available fields")
123print("-" * 40)
124
125fields_response = client.get_fields()
126print(f"API Status: {fields_response.api_status}")
127print(f"Field Count: {fields_response.field_count}")
128print(f"Fields: {fields_response.fields}")
129print(f"Last Updated: {fields_response.last_data_updated_date}")