Skip to content

Refactor downloads#35

Merged
dpieski merged 7 commits into
mainfrom
refactor-downloads
Dec 31, 2025
Merged

Refactor downloads#35
dpieski merged 7 commits into
mainfrom
refactor-downloads

Conversation

@dpieski
Copy link
Copy Markdown
Contributor

@dpieski dpieski commented Dec 31, 2025

Summary

Refactors download functionality across all clients, adds session sharing, and fixes model inconsistencies.

Changes

Download Architecture

  • Added download_file() and download_archive() base methods in BaseUSPTOClient
  • Added save_response_to_file() helper for file saving with overwrite protection
  • Standardized download behavior across Patent Data, PTAB Trials, PTAB Appeals, PTAB Interferences, and Petition Decisions clients
  • Added USPTODownloadError exception

Session Sharing

  • Clients sharing the same USPTOConfig instance now share HTTP sessions
  • Added context manager support for automatic resource cleanup
  • Added close() method for manual session cleanup

Configuration

  • Added download_chunk_size parameter to HTTPConfig (default: 8192 bytes)
  • Streaming downloads with configurable buffer sizes

Pagination

  • Enhanced paginate_results() to support both GET and POST methods via post_body parameter
  • paginate_decisions() now uses POST for complex queries
  • Automatic offset/limit management for POST bodies

Model Changes

Patent Data Models

  • Changed PatentFileWrapper.application_number_text from str | None = None to str (required)
  • Defaults to empty string when missing from API response
  • Added DocumentMimeType enum
  • Added Document.has_format() and Document.get_format() methods
  • Added DocumentBag.filter_by_format() method

PTAB Models

  • Restored documentCategory field in TrialDocumentData
  • Properly serialized in to_dict() and deserialized in from_dict()

Error Handling

  • POST request bodies now included in error messages
  • Improved error context for debugging

Tests

  • Added download tests for all clients
  • Added PTAB download integration tests
  • Fixed PTAB Appeals fixture scope from function to class

Commits

  • c1fba98 update tests based on document class improvements
  • 176de5a refactor downloads
  • 6ab1224 Update tests and README examples
  • 0cd0057 improve paginate_decisions with POST support
  • 548df75 Configurable Download Chunk Size
  • 6d4088b implement session sharing

Related Issues

Closes #27

@dpieski dpieski merged commit 089b26f into main Dec 31, 2025
7 checks passed
@dpieski dpieski deleted the refactor-downloads branch January 7, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] download_document improvement

1 participant