1"""Example usage of pyUSPTO for IFW data.
2
3This example demonstrates how to use the PatentDataClient to interact with the USPTO Patent Data API.
4It shows how to retrieve IFW based on various identifying values.
5"""
6
7import json
8import os
9
10from pyUSPTO.clients.patent_data import PatentDataClient
11from pyUSPTO.config import USPTOConfig
12
13api_key = os.environ.get("USPTO_API_KEY", "YOUR_API_KEY_HERE")
14if api_key == "YOUR_API_KEY_HERE":
15 raise ValueError(
16 "WARNING: API key is not set. Please replace 'YOUR_API_KEY_HERE' or set USPTO_API_KEY environment variable."
17 )
18config = USPTOConfig(api_key=api_key)
19client = PatentDataClient(config=config)
20
21
22print("\nBeginning API requests with configured client:")
23
24print("\nGet IFW Based on Application Number ->")
25application_number = "14412875"
26app_no_ifw = client.get_IFW_metadata(application_number=application_number)
27if app_no_ifw and app_no_ifw.application_meta_data:
28 print(f"Title: {app_no_ifw.application_meta_data.invention_title}")
29 print(f" - IFW Found based on App No: {application_number}")
30
31
32print("\nGet IFW Based on Patent Number ->")
33patent_number = "10765880"
34pat_no_ifw = client.get_IFW_metadata(patent_number=patent_number)
35if pat_no_ifw and pat_no_ifw.application_meta_data:
36 print(f"Title: {pat_no_ifw.application_meta_data.invention_title}")
37 print(f" - IFW Found based on Pat No: {patent_number}")
38
39
40print("\nGet IFW Based on Publication Number ->")
41publication_number = "*20150157873*"
42pub_no_ifw = client.get_IFW_metadata(publication_number=publication_number)
43if pub_no_ifw and pub_no_ifw.application_meta_data:
44 print(f"Title: {pub_no_ifw.application_meta_data.invention_title}")
45 print(f" - IFW Found based on Pub No: {publication_number}")
46
47
48print("\nGet IFW Based on PCT App Number ->")
49PCT_app_number = "PCT/US2008/12705"
50pct_app_no_ifw = client.get_IFW_metadata(PCT_app_number=PCT_app_number)
51if pct_app_no_ifw and pct_app_no_ifw.application_meta_data:
52 print(f"Title: {pct_app_no_ifw.application_meta_data.invention_title}")
53 print(f" - IFW Found based on PCT App No: {PCT_app_number}")
54
55
56print("\nGet IFW Based on PCT Pub Number ->")
57PCT_pub_number = "*2009064413*"
58pct_pub_no_ifw = client.get_IFW_metadata(PCT_pub_number=PCT_pub_number)
59if pct_pub_no_ifw and pct_pub_no_ifw.application_meta_data:
60 print(f"Title: {pct_pub_no_ifw.application_meta_data.invention_title}")
61 print(f" - IFW Found based on PCT Pub No: {PCT_pub_number}")
62
63
64print("\nNow let's download the Patent Publication Text -->")
65if app_no_ifw and app_no_ifw.pgpub_document_meta_data:
66 pgpub_archive = app_no_ifw.pgpub_document_meta_data
67 print(json.dumps(pgpub_archive.to_dict(), indent=2))
68 download_path = "./download-example"
69 file_path = client.download_archive(
70 printed_metadata=pgpub_archive, destination=download_path, overwrite=True
71 )
72 print(f"-Downloaded document to: {file_path}")
73
74print("\nNow let's download the Patent Grant Text -->")
75if app_no_ifw and app_no_ifw.grant_document_meta_data:
76 grant_archive = app_no_ifw.grant_document_meta_data
77 print(json.dumps(grant_archive.to_dict(), indent=2))
78 download_path = "./download-example"
79 file_path = client.download_archive(
80 printed_metadata=grant_archive, destination=download_path, overwrite=True
81 )
82 print(f"-Downloaded document to: {file_path}")