Skip to main content

A Modern Python client for accessing United Stated Patent and Trademark Office (USPTO) Open Data Portal (ODP) APIs.

Project description

pyUSPTO

PyPI version License: MIT Python 3.10+ Read the Docs

A Python client library for interacting with the United Stated Patent and Trademark Office (USPTO) Open Data Portal APIs.

This package provides clients for interacting with the USPTO Bulk Data API, the USPTO Patent Data API, and the USPTO Final Petition Decisions API.

[!IMPORTANT] The USPTO is in the process of moving their API. This package is only concerned with the new API. The old API will be retired at the end of 2025.

Quick Start

Installation

Requirements: Python ≥3.10

pip install pyUSPTO

Or install from source:

git clone https://github.com/DunlapCoddingPC/pyUSPTO.git
cd pyUSPTO
pip install -e .

Configuration Options

[!IMPORTANT] You must have an API key for the USPTO Open Data Portal API.

There are multiple ways to configure the USPTO API clients:

from pyUSPTO import PatentDataClient, FinalPetitionDecisionsClient

# Method 1: Direct API key initialization
patent_client = PatentDataClient(api_key="your_api_key_here")
petition_client = FinalPetitionDecisionsClient(api_key="your_api_key_here")

# Method 2: Using USPTOConfig with explicit parameters
from pyUSPTO.config import USPTOConfig
config = USPTOConfig(
    api_key="your_api_key_here",
    bulk_data_base_url="https://api.uspto.gov",
    patent_data_base_url="https://api.uspto.gov",
    petition_decisions_base_url="https://api.uspto.gov"
)
patent_client = PatentDataClient(config=config)
petition_client = FinalPetitionDecisionsClient(config=config)

# Method 3: Using environment variables (recommended for production)
import os
os.environ["USPTO_API_KEY"] = "your_api_key_here"
config_from_env = USPTOConfig.from_env()
patent_client = PatentDataClient(config=config_from_env)
petition_client = FinalPetitionDecisionsClient(config=config_from_env)

Advanced HTTP Configuration

Control timeout behavior, retry logic, and connection pooling using HTTPConfig:

from pyUSPTO import PatentDataClient, USPTOConfig, HTTPConfig

# Create HTTP configuration
http_config = HTTPConfig(
    timeout=60.0,              # 60 second read timeout
    connect_timeout=10.0,      # 10 seconds to establish connection
    max_retries=5,             # Retry up to 5 times on failure
    backoff_factor=2.0,        # Exponential backoff: 2, 4, 8, 16, 32 seconds
    retry_status_codes=[429, 500, 502, 503, 504],  # Retry on these status codes
    pool_connections=20,       # Connection pool size
    pool_maxsize=20,          # Max connections per pool
    custom_headers={          # Additional headers for all requests
        "User-Agent": "MyApp/1.0",
        "X-Tracking-ID": "abc123"
    }
)

# Pass HTTPConfig via USPTOConfig
config = USPTOConfig(
    api_key="your_api_key",
    http_config=http_config
)

client = PatentDataClient(config=config)

Configure HTTP settings via environment variables:

export USPTO_REQUEST_TIMEOUT=60.0       # Read timeout
export USPTO_CONNECT_TIMEOUT=10.0       # Connection timeout
export USPTO_MAX_RETRIES=5              # Max retry attempts
export USPTO_BACKOFF_FACTOR=2.0         # Retry backoff multiplier
export USPTO_POOL_CONNECTIONS=20        # Connection pool size
export USPTO_POOL_MAXSIZE=20            # Max connections per pool

Then create config from environment:

config = USPTOConfig.from_env()  # Reads both API and HTTP config from env
client = PatentDataClient(config=config)

Share HTTP configuration across multiple clients:

# Create once, use multiple times
http_config = HTTPConfig(timeout=60.0, max_retries=5)

patent_config = USPTOConfig(api_key="key1", http_config=http_config)
petition_config = USPTOConfig(api_key="key2", http_config=http_config)

patent_client = PatentDataClient(config=patent_config)
petition_client = FinalPetitionDecisionsClient(config=petition_config)

Patent Data API

# Search for applications by inventor name
inventor_search = patent_client.search_applications(inventor_name_q="Smith")
print(f"Found {inventor_search.count} applications with 'Smith' as inventor")
# > Found 104926 applications with 'Smith' as inventor.

Final Petition Decisions API

# Search for petition decisions by date range
decisions = petition_client.search_decisions(
    decision_date_from_q="2023-01-01",
    limit=10
)
print(f"Found {decisions.count} petition decisions since 2023")

# Get a specific decision by ID
decision = petition_client.get_decision_by_id("decision_id_here")
print(f"Decision Type: {decision.decision_type_code}")
print(f"Application: {decision.application_number_text}")

Warning Control

The library uses Python's standard warnings module to report data parsing issues. This allows you to control how warnings are handled based on your needs.

Warning Categories

All warnings inherit from USPTODataWarning:

  • USPTODateParseWarning: Date/datetime string parsing failures
  • USPTOBooleanParseWarning: Y/N boolean string parsing failures
  • USPTOTimezoneWarning: Timezone-related issues
  • USPTOEnumParseWarning: Enum value parsing failures

Controlling Warnings

import warnings
from pyUSPTO.warnings import (
    USPTODataWarning,
    USPTODateParseWarning,
    USPTOBooleanParseWarning,
    USPTOTimezoneWarning,
    USPTOEnumParseWarning
)

# Suppress all pyUSPTO data warnings
warnings.filterwarnings('ignore', category=USPTODataWarning)

# Suppress only date parsing warnings
warnings.filterwarnings('ignore', category=USPTODateParseWarning)

# Turn warnings into errors (strict mode)
warnings.filterwarnings('error', category=USPTODataWarning)

# Show warnings once per location
warnings.filterwarnings('once', category=USPTODataWarning)

# Always show all warnings (default Python behavior)
warnings.filterwarnings('always', category=USPTODataWarning)

The library's permissive parsing philosophy returns None for fields that cannot be parsed, allowing you to retrieve partial data even when some fields have issues. Warnings inform you when this happens without stopping execution.

Features

  • Access to USPTO Bulk Data API, Patent Data API, and Final Petition Decisions API
  • Search for patent applications using various filters
  • Search and retrieve petition decisions with detailed information
  • Download files, documents, and petition decision documents from the APIs
  • Pagination support for large result sets
  • Full type annotations and comprehensive test coverage

Documentation

Full documentation may be found on Read the Docs.

Data Models

The library uses Python dataclasses to represent API responses. All data models include type annotations for attributes and methods, making them fully compatible with static type checkers.

Bulk Data API

  • BulkDataResponse: Top-level response from the API
  • BulkDataProduct: Information about a specific product
  • ProductFileBag: Container for file data elements
  • FileData: Information about an individual file

Patent Data API

  • PatentDataResponse: Top-level response from the API
  • PatentFileWrapper: Information about a patent application
  • ApplicationMetaData: Metadata about a patent application
  • Address: Represents an address in the patent data
  • Person, Applicant, Inventor, Attorney: Person-related data classes
  • Assignment, Assignor, Assignee: Assignment-related data classes
  • Continuity, ParentContinuity, ChildContinuity: Continuity-related data classes
  • PatentTermAdjustmentData: Patent term adjustment information
  • And many more specialized classes for different aspects of patent data

Final Petition Decisions API

  • PetitionDecisionResponse: Top-level response from the API
  • PetitionDecision: Complete information about a petition decision
  • PetitionDecisionDocument: Document associated with a petition decision
  • DocumentDownloadOption: Download options for petition documents
  • DecisionTypeCode: Enum for petition decision types
  • DocumentDirectionCategory: Enum for document direction categories

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyuspto-0.2.2.tar.gz (8.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyuspto-0.2.2-py3-none-any.whl (61.3 kB view details)

Uploaded Python 3

File details

Details for the file pyuspto-0.2.2.tar.gz.

File metadata

  • Download URL: pyuspto-0.2.2.tar.gz
  • Upload date:
  • Size: 8.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyuspto-0.2.2.tar.gz
Algorithm Hash digest
SHA256 80ed15bedf88c957f4ff4b55f1d4d1ecb2e9b022a8272d2674889bc8f20c1213
MD5 2f0d67a25354ee84e77c04405b9b5de3
BLAKE2b-256 8ed68d7e3c9a7fd72b50be794ba63a57e9c98981f9682573d2458d38d0320ce5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyuspto-0.2.2.tar.gz:

Publisher: publish-to-test-pypi.yml on DunlapCoddingPC/pyUSPTO

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyuspto-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyuspto-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 61.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyuspto-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 013481b006c9fb35b559530e07494810fd58cd53fdeab4ca1c53129e38729411
MD5 83d35775c1cdbae70e36c08d04ad07b2
BLAKE2b-256 d2bc5186c932c46b1ad12b59e152b151a3ccd409221e7246b044fc8750d3079a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyuspto-0.2.2-py3-none-any.whl:

Publisher: publish-to-test-pypi.yml on DunlapCoddingPC/pyUSPTO

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page