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