A basic example

Let’s start with a basic example of how to use the package’s primary function, search_pv():

This call to search_pv() sends our query to the patents endpoint (the default). The API has 7 different endpoints, corresponding to 7 different entity types (assignees, CPC subsections, inventors, locations, NBER subcategories, patents, and USPC main classes).1 Your choice of endpoint determines which entity your query is applied to, as well as the structure of the data that is returned (more on this in the “7 endpoints for 7 entities section”). For now, let’s turn our attention to the query parameter.

Writing queries

The PatentsView query syntax is documented on their query language page.2 However, it can be difficult to get your query right if you’re writing it by hand (i.e., just writing the query in a string like '{"_gte":{"patent_date":"2007-01-01"}}', as we did in the example shown above). The patentsview package comes with a simple domain specific language (DSL) to make writing queries a breeze. I recommend using the functions in this DSL for all but the most basic queries, especially if you’re encountering errors and don’t understand why. To get a feel for how it works, let’s rewrite the query shown above using one of the functions in the DSL, qry_funs$gte():

More complex queries are also possible:

Check out the writing queries vignette for more details on using the DSL.


Each endpoint has a different set of queryable and retrievable fields. Queryable fields are those that you can include in your query (e.g., patent_date shown in the first example). Retrievable fields are those that you can get data on (i.e., fields returned by search_pv()). In the first example, we didn’t specify which fields we wanted to retrieve so we were given the default set. You can specify which fields you want using the fields argument:

To list all of the retrievable fields for a given endpoint, use get_fields():

You can also visit an endpoint’s online documentation page to see a list of its queryable and retrievable fields (e.g., see the inventor field list table). Note the “Query” column in this table, which indicates whether the field is both queryable and retrievable (Query = Y), or just retrievable (Query = N). The field tables for all of the endpoints can be found in the fieldsdf data frame, which you can load using data("fieldsdf") or View(patentsview::fieldsdf).

An important note: By default, PatentsView uses disambiguted versions of assignees, inventors, and locations, instead of raw data. For example, let’s say you search for all inventors whose first name is “john.” The PatentsView API is going to return all of the inventors who have a preferred first name (as per the disambiguation results) of john, which may not necessarily be their raw first name. You could be getting back inventors whose first name appears on the patent as, say, “jonathan,” “johnn,” or even “john jay.” You can search on the raw inventor names instead of the preferred names by using the fields starting with “raw” in your query (e.g., rawinventor_first_name). The assignee and location raw data fields are not currently being offered by the API. To see the methods behind the disambiguation process, see the PatentsView Inventor Disambiguation Technical Workshop website.

Paginated responses

By default, search_pv() returns 25 records per page and only gives you the first page of results. I suggest sticking with these defaults while you’re figuring out the details of your request, such as the query you want to use and the fields you want returned. Once you have those items finalized, you can use the per_page argument to download up to 10,000 records per page. You can also choose which page of results you want with the page argument:

You can download all pages of output in one call by setting all_pages = TRUE. This will set per_page equal to 10,000 and loop over all pages of output (downloading up to 10 pages, or 100,000 records total):

Entity counts

Our last two calls to search_pv() gave the same value for total_patent_count, even though we got a lot more data from the second call. This is because the entity counts returned by the API refer to the number of distinct entities across all downloadable pages of output, not just the page that was returned. Downloadable pages of output is an important phrase here, as the API limits us to 100,000 records per query. For example, we got total_patent_count = 100,000 when we searched for patents published on or after 2007, even though there are way more than 100,000 such patents. See the FAQs below for details on how to overcome the 100,000 record restriction.

7 endpoints for 7 entities

We can get similar data from the 7 endpoints. For example, the following two calls differ only in the endpoint that is chosen:

Your choice of endpoint determines two things:

  1. Which entity your query is applied to. The first call shown above used the patents endpoint, so the API searched for patents that have at least one inventor listed on them with the last name “chambers.” The second call used the assignees endpoint, so the API searched for all assignees that have been assigned to at least one patent which has an inventor listed on it with the last name “chambers.”

  2. The structure of the data frame that is returned. The first call returned a data frame on the patent level, meaning that each row corresponded to a different patent. Fields that were not on the patent level (e.g., inventor_last_name) were returned in list columns that are named after the entity associated with the field (e.g., the inventors entity).3 Meanwhile, the second call gave us a data frame on the assignee level (one row for each assignee) because it used the assignees endpoint.

Most of the time you will want to use the patents endpoint. Note that you can still effectively filter on fields that are not at the patent-level when using the patents endpoint (e.g., you can filter on assignee name or CPC category). This is because patents are relatively low-level entities. For higher level entities like assignees, if you filter on a field that is not at the assignee-level (e.g., inventor name), the API will return data on any assignee that has at least one inventor whose name matches your search, which is probably not what you want.


I’m sure my query is well formatted and correct but I keep getting an error. What’s the deal?

The API query syntax guidelines do not cover all of the API’s behavior. Specifically, there are several things that you cannot do which are not documented on the API’s webpage. The writing queries vignette has more details on this.

Does the API have any rate limiting/throttling controls?

Not at the moment.

How do I download more than 100,000 records?

Your best bet is to split your query into pieces based on dates, then concatenate the results together. For example, the below query would return more than 100,000 records for the patents endpoint:

query <- with_qfuns(text_any(patent_abstract = 'tool animal'))

To download all of the records associated with this query, we could split it into two pieces and make two calls to search_pv():

How do I access the data frames inside the list columns returned by search_pv()?

Let’s consider the following data, in which assignees are the primary entity while applications and “government interest statements” are the secondary entities (also referred to as subentities):

res$data has vector columns for those fields that belong to the primary entity (e.g., res$data$assignees$assignee_id) and list columns for those fields that belong to any secondary entity (e.g., res$data$assignees$applications). You have two good ways to pull out the data frames that are nested inside these list columns:

  1. Use tidyr::unnest. (This is probably the easier choice of the two).

# Get assignee/application data:
res$data$assignees %>% 
  unnest(applications) %>%
#>                 assignee_id               assignee_organization
#> 1 02xn8fhaz3q30xp85pe4m6qgv                           Elwha LLC
#> 2 0pey9wtquqe8ax6lhko0ns37u   The Invention Science Fund I, LLC
#> 3 0wewv4rkr81gvsclelevjvw5s GM Global Technology Operations LLC
#> 4 0xcna0c174o0s32u9od8ai9jh   The Invention Science Fund I, LLC
#> 5 13s82rr5ter3h43kerytpfbt1              Blazing Products, Inc.
#> 6 1d128qrg5qx4cc1a0mzg86wf5                  Hammer Tight, Inc.
#>                gov_interests app_country   app_date app_number app_type
#> 1 NA, NA, NA, NA, NA, NA, NA          US 2014-04-21   14257386       14
#> 2 NA, NA, NA, NA, NA, NA, NA          US 2010-05-21   12800793       12
#> 3 NA, NA, NA, NA, NA, NA, NA          US 2010-01-05   12652251       12
#> 4 NA, NA, NA, NA, NA, NA, NA          US 2007-04-11   11786775       11
#> 5 NA, NA, NA, NA, NA, NA, NA          US 2012-09-26   13627265       13
#> 6 NA, NA, NA, NA, NA, NA, NA          US 2013-05-23   13901095       13
#>      app_id
#> 1 14/257386
#> 2 12/800793
#> 3 12/652251
#> 4 11/786775
#> 5 13/627265
#> 6 13/901095

# Get assignee/gov_interest data:
res$data$assignees %>% 
  unnest(gov_interests) %>%
#>                 assignee_id               assignee_organization
#> 1 02xn8fhaz3q30xp85pe4m6qgv                           Elwha LLC
#> 2 0pey9wtquqe8ax6lhko0ns37u   The Invention Science Fund I, LLC
#> 3 0wewv4rkr81gvsclelevjvw5s GM Global Technology Operations LLC
#> 4 0xcna0c174o0s32u9od8ai9jh   The Invention Science Fund I, LLC
#> 5 13s82rr5ter3h43kerytpfbt1              Blazing Products, Inc.
#> 6 1d128qrg5qx4cc1a0mzg86wf5                  Hammer Tight, Inc.
#>                              applications govint_contract_award_number
#> 1 US, 2014-04-21, 14257386, 14, 14/257386                           NA
#> 2 US, 2010-05-21, 12800793, 12, 12/800793                           NA
#> 3 US, 2010-01-05, 12652251, 12, 12/652251                           NA
#> 4 US, 2007-04-11, 11786775, 11, 11/786775                           NA
#> 5 US, 2012-09-26, 13627265, 13, 13/627265                           NA
#> 6 US, 2013-05-23, 13901095, 13, 13/901095                           NA
#>   govint_org_id govint_org_level_one govint_org_level_three
#> 1          <NA>                 <NA>                     NA
#> 2          <NA>                 <NA>                     NA
#> 3          <NA>                 <NA>                     NA
#> 4          <NA>                 <NA>                     NA
#> 5          <NA>                 <NA>                     NA
#> 6          <NA>                 <NA>                     NA
#>   govint_org_level_two govint_org_name govint_raw_statement
#> 1                 <NA>            <NA>                 <NA>
#> 2                 <NA>            <NA>                 <NA>
#> 3                 <NA>            <NA>                 <NA>
#> 4                 <NA>            <NA>                 <NA>
#> 5                 <NA>            <NA>                 <NA>
#> 6                 <NA>            <NA>                 <NA>
  1. Use patentsview::unnest_pv_data. unnest_pv_data() creates a series of data frames (one for each entity level) that are like tables in a relational database. You provide it with the data returned by search_pv() and a field that can act as a unique identifier for the primary entities:

Now we are left with a series of flat data frames instead of having a single data frame with other data frames nested inside of it. These flat data frames can be joined together as needed via the primary key (assignee_id).

  1. You can use get_endpoints() to list the endpoint names as the API expects them to appear (e.g., assignees, cpc_subsections, inventors, locations, nber_subcategories, patents, and uspc_mainclasses).

  2. This webpage includes some details that are not relevant to the query argument in search_pv, such as the field list and sort parameter.

  3. You can unnest the data frames that are stored in the list columns using unnest_pv_data(). See the FAQs for details.