Skip to content
Edit this page View source of this page

pdf_remote_converter

pdf_remote_converter package.

Modules:

  • cli –

    CLI module for PDF Remote Converter.

  • config –

    Configuration settings for PDF Remote Converter.

  • converter –

    High-level converter facade for programmatic usage.

  • estimator –

    Estimate conversion timeout based on document complexity.

  • exceptions –

    Custom exception types for provider conversion errors.

  • http –

    HTTP client utilities with caching support.

  • logging –

    Logging configuration for PDF Remote Converter.

  • providers –

    Provider abstractions and registry helpers.

  • router –

    Provider routing and failover helpers.

Classes:

Functions:

  • get_provider –

    Return the provider backend class for the given name.

AdobeProvider

AdobeProvider(
    client_id: str,
    client_secret: str,
    http_client: Client | None = None,
    *,
    poll_timeout: int = 120,
)

Bases: AbstractProvider

Adobe PDF Services API implementation.

Methods:

  • convert –

    Convert the input file to PDF.

  • is_healthy –

    Return True when the provider is available and configured.

Attributes:

  • max_file_size (int | None) –

    Return the maximum file size in bytes, or None if no limit.

Source code in src/pdf_remote_converter/providers/adobe.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def __init__(
    self,
    client_id: str,
    client_secret: str,
    http_client: httpx.Client | None = None,
    *,
    poll_timeout: int = 120,
) -> None:
    """Initialize Adobe provider with credentials and HTTP client."""
    self.client_id = client_id
    self.client_secret = client_secret
    self.http_client = http_client or create_cached_client()
    self.supported_formats = {"doc", "docx", "xls", "xlsx", "ppt", "pptx"}
    self.monthly_quota = 500
    self.quota_remaining = self.monthly_quota
    self.name = "adobe"
    self.poll_timeout = poll_timeout

max_file_size property

max_file_size: int | None

Return the maximum file size in bytes, or None if no limit.

convert

convert(
    input_path: Path, output_path: Path
) -> ConversionResult

Convert the input file to PDF.

Performs format and file size validation before delegating to the provider-specific implementation via _perform_convert().

Source code in src/pdf_remote_converter/providers/base.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def convert(self, input_path: Path, output_path: Path) -> ConversionResult:
    """Convert the input file to PDF.

    Performs format and file size validation before delegating to
    the provider-specific implementation via _perform_convert().
    """
    input_format = input_path.suffix.lstrip(".").lower()
    if input_format not in self.supported_formats:
        raise InvalidFormatError(f"Format '{input_format}' is not supported by {self.name}.")

    if self.max_file_size is not None:
        file_size = input_path.stat().st_size
        if file_size > self.max_file_size:
            raise FileTooLargeError(f"{self.name} supports files up to {self.max_file_size} bytes.")

    return self._perform_convert(input_path, output_path)

is_healthy

is_healthy() -> bool

Return True when the provider is available and configured.

Source code in src/pdf_remote_converter/providers/adobe.py
57
58
59
def is_healthy(self) -> bool:
    """Return True when the provider is available and configured."""
    return bool(self.client_id and self.client_secret) and self.quota_remaining > 0

ApyHubProvider

ApyHubProvider(
    api_key: str,
    http_client: Client | None = None,
    *,
    poll_timeout: int = 120,
)

Bases: AbstractProvider

ApyHub file conversion API implementation.

Supports synchronous conversion of Word (.doc, .docx), Spreadsheet (.xls, .xlsx), and Presentation (.ppt, .pptx) documents to PDF via three dedicated endpoints.

Methods:

  • convert –

    Convert the input file to PDF.

  • is_healthy –

    Return True when the provider is available and configured.

Attributes:

  • max_file_size (int | None) –

    Return the maximum file size in bytes, or None if no limit.

Source code in src/pdf_remote_converter/providers/apyhub.py
41
42
43
44
45
46
47
48
49
def __init__(self, api_key: str, http_client: httpx.Client | None = None, *, poll_timeout: int = 120) -> None:
    """Initialize ApyHub provider with API key and HTTP client."""
    self.api_key = api_key
    self.http_client = http_client or create_cached_client()
    self.supported_formats = {"doc", "docx", "xls", "xlsx", "ppt", "pptx"}
    self.monthly_quota = 150
    self.quota_remaining = self.monthly_quota
    self.name = "apyhub"
    self.poll_timeout = poll_timeout

max_file_size property

max_file_size: int | None

Return the maximum file size in bytes, or None if no limit.

convert

convert(
    input_path: Path, output_path: Path
) -> ConversionResult

Convert the input file to PDF.

Performs format and file size validation before delegating to the provider-specific implementation via _perform_convert().

Source code in src/pdf_remote_converter/providers/base.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def convert(self, input_path: Path, output_path: Path) -> ConversionResult:
    """Convert the input file to PDF.

    Performs format and file size validation before delegating to
    the provider-specific implementation via _perform_convert().
    """
    input_format = input_path.suffix.lstrip(".").lower()
    if input_format not in self.supported_formats:
        raise InvalidFormatError(f"Format '{input_format}' is not supported by {self.name}.")

    if self.max_file_size is not None:
        file_size = input_path.stat().st_size
        if file_size > self.max_file_size:
            raise FileTooLargeError(f"{self.name} supports files up to {self.max_file_size} bytes.")

    return self._perform_convert(input_path, output_path)

is_healthy

is_healthy() -> bool

Return True when the provider is available and configured.

Source code in src/pdf_remote_converter/providers/apyhub.py
51
52
53
def is_healthy(self) -> bool:
    """Return True when the provider is available and configured."""
    return bool(self.api_key) and self.quota_remaining > 0

CloudConvertProvider

CloudConvertProvider(
    api_key: str,
    http_client: Client | None = None,
    *,
    poll_timeout: int = 120,
)

Bases: AbstractProvider

CloudConvert API implementation.

Methods:

  • convert –

    Convert the input file to PDF.

  • is_healthy –

    Return True when the provider is available and configured.

Attributes:

  • max_file_size (int | None) –

    Return the maximum file size in bytes, or None if no limit.

Source code in src/pdf_remote_converter/providers/cloudconvert.py
28
29
30
31
32
33
34
35
36
def __init__(self, api_key: str, http_client: httpx.Client | None = None, *, poll_timeout: int = 120) -> None:
    """Initialize CloudConvert provider with API key and HTTP client."""
    self.api_key = api_key
    self.http_client = http_client or create_cached_client()
    self.supported_formats = {"doc", "docx", "xls", "xlsx", "ppt", "pptx"}
    self.monthly_quota = 300
    self.quota_remaining = self.monthly_quota
    self.name = "cloudconvert"
    self.poll_timeout = poll_timeout

max_file_size property

max_file_size: int | None

Return the maximum file size in bytes, or None if no limit.

convert

convert(
    input_path: Path, output_path: Path
) -> ConversionResult

Convert the input file to PDF.

Performs format and file size validation before delegating to the provider-specific implementation via _perform_convert().

Source code in src/pdf_remote_converter/providers/base.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def convert(self, input_path: Path, output_path: Path) -> ConversionResult:
    """Convert the input file to PDF.

    Performs format and file size validation before delegating to
    the provider-specific implementation via _perform_convert().
    """
    input_format = input_path.suffix.lstrip(".").lower()
    if input_format not in self.supported_formats:
        raise InvalidFormatError(f"Format '{input_format}' is not supported by {self.name}.")

    if self.max_file_size is not None:
        file_size = input_path.stat().st_size
        if file_size > self.max_file_size:
            raise FileTooLargeError(f"{self.name} supports files up to {self.max_file_size} bytes.")

    return self._perform_convert(input_path, output_path)

is_healthy

is_healthy() -> bool

Return True when the provider is available and configured.

Source code in src/pdf_remote_converter/providers/cloudconvert.py
38
39
40
def is_healthy(self) -> bool:
    """Return True when the provider is available and configured."""
    return bool(self.api_key) and self.quota_remaining > 0

ConversionResult dataclass

ConversionResult(
    output_path: Path,
    provider: str,
    from_cache: bool,
    credits_used: int,
)

Converter

Converter(
    provider: str | None = None,
    api_key: str | None = None,
    settings: ProviderSettings | None = None,
)

High-level converter API for programmatic usage.

Methods:

  • convert –

    Convert an input document to PDF.

Source code in src/pdf_remote_converter/converter.py
19
20
21
22
23
24
25
26
27
28
def __init__(
    self,
    provider: str | None = None,
    api_key: str | None = None,
    settings: ProviderSettings | None = None,
) -> None:
    """Initialize converter with optional provider overrides."""
    self.settings = settings or ProviderSettings()
    self.provider_override = provider
    self.api_key_override = api_key

convert

convert(
    input_path: str | Path, output_path: str | Path
) -> ConversionResult

Convert an input document to PDF.

Source code in src/pdf_remote_converter/converter.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def convert(self, input_path: str | Path, output_path: str | Path) -> ConversionResult:
    """Convert an input document to PDF."""
    input_path = Path(input_path)
    output_path = Path(output_path)

    settings = self.settings
    if self.api_key_override:
        settings.api_key = self.api_key_override

    providers = get_configured_providers(settings)

    if self.provider_override:
        selected = select_provider(self.provider_override, settings)
        providers = [selected]

    return convert_with_failover(
        input_path,
        output_path,
        providers,
        min_timeout=self.settings.poll_timeout_min,
        max_timeout=self.settings.poll_timeout_max,
    )

GoogleDriveProvider

GoogleDriveProvider(
    credentials_path: Path,
    http_client: Client | None = None,
    *,
    poll_timeout: int = 120,
)

Bases: AbstractProvider

Google Drive file conversion via upload-export-delete flow.

Uploads an Office file to Google Drive, exports it as PDF using Google Docs/Sheets/Slides conversion, then deletes the temporary file. Authentication uses a Google Cloud Service Account (JSON key file).

Parameters:

  • credentials_path

    (Path) –

    Path to the service account JSON key file.

  • http_client

    (Client | None, default: None ) –

    Optional cached HTTP client (created if not provided).

  • poll_timeout

    (int, default: 120 ) –

    Timeout in seconds for API requests.

Methods:

  • convert –

    Convert the input file to PDF.

  • is_healthy –

    Return True when credentials are loaded and valid.

Attributes:

  • max_file_size (int | None) –

    Return the maximum file size in bytes, or None if no limit.

Source code in src/pdf_remote_converter/providers/google_drive.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(
    self,
    credentials_path: Path,
    http_client: httpx.Client | None = None,
    *,
    poll_timeout: int = 120,
) -> None:
    """Initialize Google Drive provider with service account credentials.

    Args:
        credentials_path: Path to the service account JSON key file.
        http_client: Optional cached HTTP client (created if not provided).
        poll_timeout: Timeout in seconds for API requests.
    """
    self.credentials_path = credentials_path
    self.http_client = http_client or create_cached_client()
    self.supported_formats = set(IMPORT_MIME_TYPES.keys())
    self.monthly_quota = 0  # effectively unlimited for individual use
    self.quota_remaining = 0
    self.name = "google_drive"
    self.poll_timeout = poll_timeout
    self._credentials: service_account.Credentials | None = self._load_credentials(credentials_path)

max_file_size property

max_file_size: int | None

Return the maximum file size in bytes, or None if no limit.

convert

convert(
    input_path: Path, output_path: Path
) -> ConversionResult

Convert the input file to PDF.

Performs format and file size validation before delegating to the provider-specific implementation via _perform_convert().

Source code in src/pdf_remote_converter/providers/base.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def convert(self, input_path: Path, output_path: Path) -> ConversionResult:
    """Convert the input file to PDF.

    Performs format and file size validation before delegating to
    the provider-specific implementation via _perform_convert().
    """
    input_format = input_path.suffix.lstrip(".").lower()
    if input_format not in self.supported_formats:
        raise InvalidFormatError(f"Format '{input_format}' is not supported by {self.name}.")

    if self.max_file_size is not None:
        file_size = input_path.stat().st_size
        if file_size > self.max_file_size:
            raise FileTooLargeError(f"{self.name} supports files up to {self.max_file_size} bytes.")

    return self._perform_convert(input_path, output_path)

is_healthy

is_healthy() -> bool

Return True when credentials are loaded and valid.

Source code in src/pdf_remote_converter/providers/google_drive.py
79
80
81
def is_healthy(self) -> bool:
    """Return True when credentials are loaded and valid."""
    return self._credentials is not None

ZamzarProvider

ZamzarProvider(
    api_key: str,
    http_client: Client | None = None,
    *,
    poll_timeout: int = 120,
)

Bases: AbstractProvider

Zamzar API implementation.

Methods:

  • convert –

    Convert the input file to PDF.

  • is_healthy –

    Return True when the provider is available and configured.

Attributes:

  • max_file_size (int | None) –

    Return the maximum file size in bytes (1MB for Zamzar free tier).

Source code in src/pdf_remote_converter/providers/zamzar.py
30
31
32
33
34
35
36
37
38
def __init__(self, api_key: str, http_client: httpx.Client | None = None, *, poll_timeout: int = 120) -> None:
    """Initialize Zamzar provider with API key and HTTP client."""
    self.api_key = api_key
    self.http_client = http_client or create_cached_client()
    self.supported_formats = {"doc", "docx", "xls", "xlsx", "ppt", "pptx"}
    self.monthly_quota = 100
    self.quota_remaining = self.monthly_quota
    self.name = "zamzar"
    self.poll_timeout = poll_timeout

max_file_size property

max_file_size: int | None

Return the maximum file size in bytes (1MB for Zamzar free tier).

convert

convert(
    input_path: Path, output_path: Path
) -> ConversionResult

Convert the input file to PDF.

Performs format and file size validation before delegating to the provider-specific implementation via _perform_convert().

Source code in src/pdf_remote_converter/providers/base.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def convert(self, input_path: Path, output_path: Path) -> ConversionResult:
    """Convert the input file to PDF.

    Performs format and file size validation before delegating to
    the provider-specific implementation via _perform_convert().
    """
    input_format = input_path.suffix.lstrip(".").lower()
    if input_format not in self.supported_formats:
        raise InvalidFormatError(f"Format '{input_format}' is not supported by {self.name}.")

    if self.max_file_size is not None:
        file_size = input_path.stat().st_size
        if file_size > self.max_file_size:
            raise FileTooLargeError(f"{self.name} supports files up to {self.max_file_size} bytes.")

    return self._perform_convert(input_path, output_path)

is_healthy

is_healthy() -> bool

Return True when the provider is available and configured.

Source code in src/pdf_remote_converter/providers/zamzar.py
45
46
47
def is_healthy(self) -> bool:
    """Return True when the provider is available and configured."""
    return bool(self.api_key) and self.quota_remaining > 0

get_provider

get_provider(name: str) -> type[ProviderBackend]

Return the provider backend class for the given name.

Source code in src/pdf_remote_converter/providers/__init__.py
14
15
16
17
18
19
20
21
22
23
24
25
26
def get_provider(name: str) -> type[ProviderBackend]:
    """Return the provider backend class for the given name."""
    providers = {
        "cloudconvert": CloudConvertProvider,
        "adobe": AdobeProvider,
        "apyhub": ApyHubProvider,
        "google_drive": GoogleDriveProvider,
        "zamzar": ZamzarProvider,
    }
    if name not in providers:
        msg = f"Provider '{name}' is not registered."
        raise ValueError(msg)
    return providers[name]