Skip to content

Add Files API v1 and Data Sources API support#18

Merged
f-ortega-g merged 12 commits into
masterfrom
files-api-v1
Jul 24, 2026
Merged

Add Files API v1 and Data Sources API support#18
f-ortega-g merged 12 commits into
masterfrom
files-api-v1

Conversation

@f-ortega-g

@f-ortega-g f-ortega-g commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds first-class support for the Files API v1, targeting the documented endpoint surface.

  • Single-document submission: file_new takes exactly one of source_uri (a remote s3://, gs://, public https://, or Azure Blob URI, via POST /files/v1/uri) or file_path (a local file, via multipart upload). Supports Idempotency-Key retry safety, (job_id, custom_id) idempotency, and the filename, s3_region, and include_page_info options. An extra_options dict (also on file_job_new) is the escape hatch for API options the SDK does not model yet, validated server-side.
  • Batch jobs: file_job_new submits documents in bulk via POST /files/v1/jobs, with a FileSubmission dataclass. The FileJob class polls job status, lists files with a status filter and a pagination iterator, and fetches files by custom_id.
  • Lifecycle methods: file_job_list, file_get, file_delete, and file_job_get. The *_get methods fetch the resource and return a handle seeded with the response, raising for unknown ids.
  • File class: status polling, downloads, delete(), and lazy status attributes; download errors are disambiguated per the API contract (format_not_ready vs not_found vs unsupported_format).
  • Data Sources API: onboarding_identities, data_source_new, data_source_list, data_source_test, data_source_delete, and a DataSource class. test() returns the probe body as-is (a failed probe is data, not an exception); secret is never logged.
  • Logging: debug logs redact remote URIs to scheme and host, since signed URLs carry credentials in their query strings.
  • Errors: FilesApiError carries the machine-readable error_id and http_status. It is raised only for responses with a recognizable Files API error body; anything else falls back to MathpixClientError.
  • Validation: the client keeps basic type/shape validation (required fields, exactly-one-source, duplicate custom_id within a batch) and rejects extra_options keys that would override validated request fields; evolving protocol constraints (identifier charset/length, per-call ceilings, filter values) are left to the server as the authority.
  • User-Agent: all requests send mpxpy/<version>.

Version bumped to 0.0.21. README and changelog updated.

Deprecations

ScsFile, scs_file_new, list_scs_files, list_scs_jobs, and scs_job_status are marked with the @deprecated decorator (PEP 702; warnings.deprecated on Python 3.13+, typing_extensions.deprecated below that) and removed from the README. They keep their existing behavior and response shapes during the deprecation window, except that scs_file_new is now a thin wrapper that translates its legacy argument names and forwards to file_new.

Tests

  • tests/test_files_api_unit.py: mocked unit tests (no credentials) covering request paths, bodies, headers, error handling and fallbacks, pagination, and every deprecated wrapper and its warning.
  • tests/test_files_api.py: integration tests for the file and job workflows and data-source management.
  • tests/test_scs.py: updated for the final deprecated-wrapper behavior.

@f-ortega-g f-ortega-g self-assigned this Jul 22, 2026
Add file_new, file_job_new, file_jobs_list, file_get, file_delete, and
file_job_get targeting the public Files API v1 endpoints, with File and
FileJob resource classes, a FileSubmission dataclass, Idempotency-Key
support, and client-side validation of custom_id/job_id constraints.
file_new submits by remote URI (POST /files/v1/uri).

Add the Data Sources API: onboarding_identities, data_source_new (with
exist_ok conflict resolution), data_sources_list, data_source_get,
data_source_test, data_source_delete, and a DataSource class.

Add FilesApiError carrying the API error code and HTTP status, correct
download error handling (format_not_ready vs not_found vs
unsupported_format), and send a mpxpy/<version> User-Agent header on all
requests.

Mark the pre-release scs_file_new, list_scs_files, list_scs_jobs, and
scs_job_status methods with the deprecated decorator and drop them from
the README; remote submissions and job queries forward to the public
endpoints. ScsFile is an alias of File.

Bump version to 0.0.21.

@kai-mathpix kai-mathpix left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comments are in the inline threads below.

Comment thread mpxpy/mathpix_client.py
Comment thread mpxpy/file.py
Comment thread mpxpy/mathpix_client.py Outdated
Comment thread mpxpy/mathpix_client.py Outdated
Comment thread mpxpy/mathpix_client.py Outdated
Comment thread mpxpy/mathpix_client.py Outdated
Comment thread changelog.md Outdated
Comment thread mpxpy/scs_file.py
Comment thread mpxpy/errors.py Outdated
Comment thread mpxpy/mathpix_client.py Outdated
- Raise on failed File.status() responses instead of caching error
  bodies as status data
- Centralize Files API error-envelope parsing; raise FilesApiError only
  for recognized error bodies and MathpixClientError otherwise
- Reject conversion_options keys that would override validated request
  fields in file_new and file_job_new
- Drop the discarded metadata "mpxpy" marker; User-Agent covers
  attribution
- Keep list_scs_jobs and scs_job_status on the legacy scs-jobs
  endpoints so deprecated callers keep the legacy response shapes
- Expose filename, s3_region, and include_page_info on file_new and
  forward them from scs_file_new instead of dropping them
- Restore ScsFile as a distinct deprecated class (minus cropped_image)
  and return it from scs_file_new again
- Add mocked Files API unit tests and update the SCS tests for the
  final behavior
- Fix the changelog and bump the version to 0.21.0
- file_new is the single submission entry point: exactly one of
  source_uri (POST /files/v1/uri) or file_path (multipart POST
  /files/v1); scs_file_new is now a thin deprecated wrapper that
  translates its legacy argument names and forwards to file_new
- Rename file_jobs_list to file_job_list per the singular-resource
  naming convention
- file_get and file_job_get now fetch the resource and return a seeded
  handle, matching app_token_get, and raise FilesApiError for unknown
  ids
- Remove client-side duplicates of server-enforced constraints: the
  200,000 items-per-call ceiling, the custom_id/Idempotency-Key charset
  and length checks, and the job file status filter enum; the server's
  FilesApiError is authoritative for those
Comment thread mpxpy/mathpix_client.py Outdated
@f-ortega-g f-ortega-g changed the title Support the public Files API v1 and Data Sources API Add Files API v1 and Data Sources API support Jul 23, 2026
@Mathpix Mathpix deleted a comment from kai-mathpix Jul 23, 2026
…ction

- Remove exist_ok from data_source_new; a registration conflict now
  raises through the centralized error parsing, preserving the server's
  conflict message
- Document only observable data-source behavior: deletion removes the
  registration without interrupting already-started work and cloud-side
  grants are revoked separately; the gcp onboarding block is optional;
  external_id is a stable per-group value; inaccessible ids report
  not_found
- Redact remote URIs in debug logs to scheme and host, and drop
  caller-controlled values that are not needed for diagnosis
- Trim the changelog to the supported public surface
- Add request-shape tests for Azure, GCP, and AWS access_key
  registration, the duplicate-name conflict, the optional gcp identity
  block, and log redaction
Comment thread mpxpy/mathpix_client.py
Comment thread pyproject.toml Outdated
Comment thread pyproject.toml Outdated
Converges the escape-hatch naming with the pattern PR #19 introduces
for the v3 methods, while the files methods are still unreleased. The
deprecated scs_file_new keeps its legacy conversion_options argument
and forwards it. The reserved-keys guard is unchanged: extra_options
adds unmodeled API options but cannot override validated request
fields.
mattmathpix
mattmathpix previously approved these changes Jul 24, 2026
Comment thread tests/test_files_api_unit.py Outdated
Comment thread README.md
- file_new(file_path=...) now forwards custom_id as a multipart form
  field and Idempotency-Key as a header, matching the URI transport;
  the remote-only language is removed from the docs
- Rename data_sources_list to data_source_list; remove the request-free
  data_source_get, with data_source_test and data_source_delete
  constructing the handle internally
- Stop enforcing and publishing evolving server constraints: drop the
  provider/auth-method tables and secret pairing check (the server
  rejects invalid combinations), and remove the numeric limits and
  identifier rules from README and docstrings; keep required-value
  checks only
- Fix the AWS access_key request-shape test to use the contract field
  name aws_access_key_id and assert the complete details body; document
  the shape in data_source_new
- Add extra_options to the README's file_job_new argument list
The multipart body carries job_id under its legacy field name, which
the reserved-keys guard did not cover, so a local-upload extra_options
dict could smuggle a conflicting job id past validation. The guard now
rejects the alias on the multipart path, and both transports treat an
explicitly supplied Idempotency-Key the same way.
The multipart endpoint prefers the job_id form field (the old alias is
deprecated server-side) and the options body accepts destination_uri
directly, so drop the legacy-name translation: job_id travels as a form
field and destination_uri keeps its public name. Verified against the
endpoint's parameter handling; the deprecated scs_file_new wrapper
still accepts its legacy argument names and translates them.
The docstrings promised files_api_url defaults to api_url, but the code
fell back to the default host, silently sending Files API requests
there for custom api_url configurations. The resolution is now explicit
argument, then MATHPIX_FILES_API_URL, then the resolved api_url, with a
unit test covering the precedence.
@f-ortega-g
f-ortega-g merged commit ac851d8 into master Jul 24, 2026
@f-ortega-g
f-ortega-g deleted the files-api-v1 branch July 24, 2026 18:41
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.

3 participants