Package: pypatent
pypatentpypatent is a tiny Python package to easily search for and scrape US Patent and Trademark Office Patent Data.PyPI pageNew in version 1.2This version implements Selenium support for scraping.
Previous versions were using therequestslibrary for all requests, however this has had problems with the USPTO site lately.
I notice some users have been able to userequestswithout issue, while others get 4xx errors.PyPatent Version 1.2 implements an optional new WebConnection object to give the user the option to use Selenium WebDrivers in place of therequestslibrary.
This WebConnection object is optional.
If used, it should be passed as an argument when initializingSearchorPatentobjects.Use it in the following cases:When you want to use Selenium instead ofrequestsWhen you want to userequestsbut with a custom user-agent or headersSee bottom of README for examples.RequirementsPython 3, BeautifulSoup, requests, pandas, re, seleniumInstallationpip install pypatentIf using Selenium for scraping (introduced in version 1.2), be sure to install a Selenium WebDriver.
For Chrome, usechromedriver. For Firefox, usegeckodriver.
Seethe Selenium download pagefor more details and options.Searching for patentsThe Search object works similarly to theAdvanced Search at the USPTO, with additional options.Specifying patent criteria for your searchThere are two methods to specify your search criteria, and you can use one or both.Search Method 1: Using a custom stringYou may search for a certain string in all fields of the patent:pypatent.Search('microsoft')# Will return results matching 'microsoft' in any fieldYou may also specify complex search criteria as demonstrated on theUSPTO site:pypatent.Search('TTL/(tennis AND (racquet OR racket))')Search Method 2: Specify USPTO search fields (see Field Codes below)Alternatively, you can specify one or more Field Code arguments to search within the specified fields. Multiple Field Code arguments will create a search with AND logic. OR logic can be used within a single argument. For more complex logic, use a custom string.pypatent.Search(pn='adobe',ttl='software')# Equivalent to search('PN/adobe AND TTL/software')pypatent.Search(pn=('adobe or macromedia'),ttl='software')# Equivalent to search('PN/(adobe or macromedia) AND TTL/software')Combining search methods 1 and 2String criteria can be used in conjunction with Field Code arguments:pypatent.Search('acrobat',pn='adobe',ttl='software')# Equivalent to search('acrobat AND PN/adobe AND TTL/software')The Field Code arguments have the same meaning as on theUSPTO site.Additional search optionsLimit the number of resultsTheresults_limitargument lets you change how many patent results are retrieved. The default is 50, equivalent to one page of results.pypatent.Search('microsoft',results_limit=10)# Fetch 10 results onlySpecify whether to fetch details for each patentBy default, pypatent retrieves the details of every patent by visiting each patent's URL from the search results.
This can take a long time since each page has to be scraped.
If you just need the patent titles and URLs from the search results, setget_patent_detailstoFalse:pypatent.Search('microsoft',get_patent_details=False)# Fetch patent numbers and titles onlyFormatting your search resultspypatent has convenience methods to format the Search object into either a Pandas DataFrame or list of dicts.Format as Pandas DataFrame:pypatent.Search('microsoft').as_dataframe()Format as list of dicts:pypatent.Search('microsoft',get_patent_details=False).as_list()Sample result (without patent details):[{
     'title': 'Electronic device',
      'url': 'http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.htm&r=1&p=1&f=G&l=50&d=PTXT&S1=microsoft&OS=microsoft&RS=microsoft'
 },

 {'title': 'Portable electric device', ... }The Patent classTheSearchclass uses thePatentclass to retrieve and store patent details for a given patent URL.
You can use it directly if you already know the patent URL (e.g. you ran a Search withget_patent_details=False)# Create a Patent objectthis_patent=pypatent.Patent(title='Base station device, first location management device, terminal device, communication control method, and communication system',url='http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.htm&r=4&p=1&f=G&l=50&d=PTXT&S1=aaa&OS=aaa&RS=aaa')# Fetch the detailsthis_patent.fetch_details()Patent Attributes Retrieved:Note, not all fields from the patent page are scraped. I hope to add more, and pull requests are appreciated :)patent_num: Patent Numberpatent_date: Issue Dateabstract: Abstractinventors: List of Names of Inventors and Their Locationsapplicant_name: Applicant Nameapplicant_city: Applicant Cityapplicant_state: Applicant Stateapplicant_country: Applicant Countryassignee_name: Assignee Nameassignee_loc: Assignee Locationfamily_id: Family IDapplicant_num: Applicant Numberfile_date: Filing dateclaims: Claims Description (as a list)description: Patent Description (as a list)Field Code Arguments for Search FunctionPN: Patent NumberISD: Issue DateTTL: TitleABST: AbstractACLM: Claim(s)SPEC: Description/SpecificationCCL: Current US ClassificationCPC: Current CPC ClassificationCPCL: Current CPC Classification ClassICL: International ClassificationAPN: Application Serial NumberAPD: Application DateAPT: Application TypeGOVT: Government InterestFMID: Patent Family IDPARN: Parent Case InformationRLAP: Related US App. DataRLFD: Related Application Filing DatePRIR: Foreign PriorityPRAD: Priority Filing DatePCT: PCT InformationPTAD: PCT Filing DatePT3D: PCT 371 DatePPPD: Prior Published Document DateREIS: Reissue DataRPAF Reissued Patent Application Filing DateAFFF: 130(b) Affirmation FlagAFFT: 130(b) Affirmation StatementIN: Inventor NameIC: Inventor CityIS: Inventor StateICN: Inventor CountryAANM: Applicant NameAACI: Applicant CityAAST: Applicant StateAACO: Applicant CountryAAAT: Applicant TypeLREP: Attorney or agentAN: Assignee NameAC: Assignee CityAS: Assignee StateACN: Assignee CountryEXP: Primary ExaminerEXA: Assistant ExaminerREF: Referenced ByFREF: Foreign ReferencesOREF: Other ReferencesCOFC: Certificate of CorrectionREEX: Re-Examination CertificatePTAB: PTAB Trial CertificateSEC: Supplemental Exam CertificateILRN: International Registration NumberILRD: International Registration DateILPD: International Registration Publication DateILFD: Hague International Filing DateChangelogNew in version 1.2This version implements Selenium support for scraping.
Previous versions were using therequestslibrary for all requests, however the USPTO site has been causing problems for it.
I notice some users have been able to userequestswithout issue, while others get 4xx errors.PyPatent Version 1.2 implements a new WebConnection object to give the user the option to use Selenium WebDrivers in place of therequestslibrary.
This WebConnection object is optional.
If used, it should be passed as an argument when initializingSearchorPatentobjects.
Use it in the following cases:When you want to use Selenium instead ofrequestsWhen you want to userequestsbut with a custom user-agent or headersAn example using the Firefox WebDriver:importpypatentfromseleniumimportwebdriverdriver=webdriver.Firefox()# Requires geckodriver in your PATHconn=pypatent.WebConnection(use_selenium=True,selenium_driver=driver)res=pypatent.Search('microsoft',get_patent_details=True,web_connection=conn)print(res)An example using therequestslibrary with a custom user agent:importpypatentconn=pypatent.WebConnection(use_selenium=False,user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36')res=pypatent.Search('microsoft',get_patent_details=True,web_connection=conn)print(res)An example using therequestslibrary with default user agent (WebConnection is not necessary here as we are using the defaults)importpypatentres=pypatent.Search('microsoft',get_patent_details=True)print(res)New in version 1.1:This version makes searching and storing patent data easier:Simplified to 2 objects:SearchandPatentASearchobject searches the USPTO site and can output the results as a DataFrame or list. It can scrape the details of each patent, or just get the patent title and URL. Most users will only need to use this object.APatentobject fetches and holds a single patent's info. Fetching the patent's details is now optional. This object should only be used when you already have the patent URL and aren't conducting a search.