formatjet 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. formatjet-0.1.0/.gitignore +47 -0
  2. formatjet-0.1.0/LICENSE +21 -0
  3. formatjet-0.1.0/PKG-INFO +126 -0
  4. formatjet-0.1.0/README.md +104 -0
  5. formatjet-0.1.0/pyproject.toml +39 -0
  6. formatjet-0.1.0/src/formatjet/__init__.py +53 -0
  7. formatjet-0.1.0/src/formatjet/_client.py +417 -0
  8. formatjet-0.1.0/src/formatjet/_errors.py +75 -0
  9. formatjet-0.1.0/src/formatjet/_transport.py +66 -0
  10. formatjet-0.1.0/src/formatjet/_webhooks.py +93 -0
  11. formatjet-0.1.0/src/formatjet/openapi/__init__.py +9 -0
  12. formatjet-0.1.0/src/formatjet/openapi/api/__init__.py +1 -0
  13. formatjet-0.1.0/src/formatjet/openapi/api/account/__init__.py +1 -0
  14. formatjet-0.1.0/src/formatjet/openapi/api/account/get_account.py +144 -0
  15. formatjet-0.1.0/src/formatjet/openapi/api/account/get_usage.py +197 -0
  16. formatjet-0.1.0/src/formatjet/openapi/api/catalog/__init__.py +1 -0
  17. formatjet-0.1.0/src/formatjet/openapi/api/catalog/get_pricing.py +128 -0
  18. formatjet-0.1.0/src/formatjet/openapi/api/catalog/list_formats.py +128 -0
  19. formatjet-0.1.0/src/formatjet/openapi/api/catalog/list_operations.py +193 -0
  20. formatjet-0.1.0/src/formatjet/openapi/api/jobs/__init__.py +1 -0
  21. formatjet-0.1.0/src/formatjet/openapi/api/jobs/cancel_job.py +220 -0
  22. formatjet-0.1.0/src/formatjet/openapi/api/jobs/convert.py +396 -0
  23. formatjet-0.1.0/src/formatjet/openapi/api/jobs/create_job.py +241 -0
  24. formatjet-0.1.0/src/formatjet/openapi/api/jobs/create_upload.py +230 -0
  25. formatjet-0.1.0/src/formatjet/openapi/api/jobs/delete_job.py +188 -0
  26. formatjet-0.1.0/src/formatjet/openapi/api/jobs/estimate_job.py +239 -0
  27. formatjet-0.1.0/src/formatjet/openapi/api/jobs/get_job.py +188 -0
  28. formatjet-0.1.0/src/formatjet/openapi/api/jobs/list_jobs.py +208 -0
  29. formatjet-0.1.0/src/formatjet/openapi/api/jobs/stream_job_events.py +194 -0
  30. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/__init__.py +1 -0
  31. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/create_webhook.py +225 -0
  32. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/delete_webhook.py +174 -0
  33. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/get_webhook.py +176 -0
  34. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/list_webhook_deliveries.py +234 -0
  35. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/list_webhooks.py +144 -0
  36. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/replay_webhook_event.py +242 -0
  37. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/rotate_webhook_secret.py +224 -0
  38. formatjet-0.1.0/src/formatjet/openapi/api/webhooks/update_webhook.py +214 -0
  39. formatjet-0.1.0/src/formatjet/openapi/client.py +280 -0
  40. formatjet-0.1.0/src/formatjet/openapi/errors.py +16 -0
  41. formatjet-0.1.0/src/formatjet/openapi/models/__init__.py +231 -0
  42. formatjet-0.1.0/src/formatjet/openapi/models/account.py +114 -0
  43. formatjet-0.1.0/src/formatjet/openapi/models/account_credits.py +102 -0
  44. formatjet-0.1.0/src/formatjet/openapi/models/account_credits_monthly_type_0.py +78 -0
  45. formatjet-0.1.0/src/formatjet/openapi/models/account_key.py +107 -0
  46. formatjet-0.1.0/src/formatjet/openapi/models/account_key_mode.py +16 -0
  47. formatjet-0.1.0/src/formatjet/openapi/models/account_key_scopes_item.py +17 -0
  48. formatjet-0.1.0/src/formatjet/openapi/models/account_limits.py +111 -0
  49. formatjet-0.1.0/src/formatjet/openapi/models/account_organization.py +69 -0
  50. formatjet-0.1.0/src/formatjet/openapi/models/account_plan.py +69 -0
  51. formatjet-0.1.0/src/formatjet/openapi/models/convert_files_body.py +75 -0
  52. formatjet-0.1.0/src/formatjet/openapi/models/convert_from.py +95 -0
  53. formatjet-0.1.0/src/formatjet/openapi/models/convert_to.py +95 -0
  54. formatjet-0.1.0/src/formatjet/openapi/models/deletion_receipt_response.py +79 -0
  55. formatjet-0.1.0/src/formatjet/openapi/models/deletion_receipt_response_receipt.py +50 -0
  56. formatjet-0.1.0/src/formatjet/openapi/models/estimate.py +136 -0
  57. formatjet-0.1.0/src/formatjet/openapi/models/estimate_credit_weight.py +70 -0
  58. formatjet-0.1.0/src/formatjet/openapi/models/estimate_from.py +95 -0
  59. formatjet-0.1.0/src/formatjet/openapi/models/estimate_request.py +79 -0
  60. formatjet-0.1.0/src/formatjet/openapi/models/estimate_request_steps_item.py +124 -0
  61. formatjet-0.1.0/src/formatjet/openapi/models/estimate_request_steps_item_from.py +95 -0
  62. formatjet-0.1.0/src/formatjet/openapi/models/estimate_request_steps_item_op.py +15 -0
  63. formatjet-0.1.0/src/formatjet/openapi/models/estimate_request_steps_item_options.py +47 -0
  64. formatjet-0.1.0/src/formatjet/openapi/models/estimate_request_steps_item_to.py +95 -0
  65. formatjet-0.1.0/src/formatjet/openapi/models/estimate_to.py +95 -0
  66. formatjet-0.1.0/src/formatjet/openapi/models/format_.py +109 -0
  67. formatjet-0.1.0/src/formatjet/openapi/models/job.py +297 -0
  68. formatjet-0.1.0/src/formatjet/openapi/models/job_error_type_0.py +69 -0
  69. formatjet-0.1.0/src/formatjet/openapi/models/job_estimate.py +61 -0
  70. formatjet-0.1.0/src/formatjet/openapi/models/job_input.py +163 -0
  71. formatjet-0.1.0/src/formatjet/openapi/models/job_input_format_type_1.py +95 -0
  72. formatjet-0.1.0/src/formatjet/openapi/models/job_input_format_type_2_type_1.py +95 -0
  73. formatjet-0.1.0/src/formatjet/openapi/models/job_input_format_type_3_type_1.py +95 -0
  74. formatjet-0.1.0/src/formatjet/openapi/models/job_inputs_item.py +165 -0
  75. formatjet-0.1.0/src/formatjet/openapi/models/job_inputs_item_format_type_1.py +95 -0
  76. formatjet-0.1.0/src/formatjet/openapi/models/job_inputs_item_format_type_2_type_1.py +97 -0
  77. formatjet-0.1.0/src/formatjet/openapi/models/job_inputs_item_format_type_3_type_1.py +97 -0
  78. formatjet-0.1.0/src/formatjet/openapi/models/job_links.py +69 -0
  79. formatjet-0.1.0/src/formatjet/openapi/models/job_metadata.py +45 -0
  80. formatjet-0.1.0/src/formatjet/openapi/models/job_mode.py +14 -0
  81. formatjet-0.1.0/src/formatjet/openapi/models/job_outputs_item.py +133 -0
  82. formatjet-0.1.0/src/formatjet/openapi/models/job_request.py +213 -0
  83. formatjet-0.1.0/src/formatjet/openapi/models/job_request_input_type_0.py +42 -0
  84. formatjet-0.1.0/src/formatjet/openapi/models/job_request_input_type_1.py +53 -0
  85. formatjet-0.1.0/src/formatjet/openapi/models/job_request_input_type_2.py +54 -0
  86. formatjet-0.1.0/src/formatjet/openapi/models/job_request_inputs_item_type_0.py +42 -0
  87. formatjet-0.1.0/src/formatjet/openapi/models/job_request_inputs_item_type_1.py +53 -0
  88. formatjet-0.1.0/src/formatjet/openapi/models/job_request_metadata.py +47 -0
  89. formatjet-0.1.0/src/formatjet/openapi/models/job_request_output.py +51 -0
  90. formatjet-0.1.0/src/formatjet/openapi/models/job_request_steps_item.py +120 -0
  91. formatjet-0.1.0/src/formatjet/openapi/models/job_request_steps_item_from.py +95 -0
  92. formatjet-0.1.0/src/formatjet/openapi/models/job_request_steps_item_op.py +15 -0
  93. formatjet-0.1.0/src/formatjet/openapi/models/job_request_steps_item_options.py +47 -0
  94. formatjet-0.1.0/src/formatjet/openapi/models/job_request_steps_item_to.py +95 -0
  95. formatjet-0.1.0/src/formatjet/openapi/models/job_status.py +29 -0
  96. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item.py +234 -0
  97. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_from_type_1.py +95 -0
  98. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_from_type_2_type_1.py +95 -0
  99. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_from_type_3_type_1.py +95 -0
  100. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_op.py +15 -0
  101. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_options.py +45 -0
  102. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_status.py +29 -0
  103. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_to_type_1.py +95 -0
  104. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_to_type_2_type_1.py +95 -0
  105. formatjet-0.1.0/src/formatjet/openapi/models/job_steps_item_to_type_3_type_1.py +95 -0
  106. formatjet-0.1.0/src/formatjet/openapi/models/job_summary.py +160 -0
  107. formatjet-0.1.0/src/formatjet/openapi/models/job_summary_mode.py +16 -0
  108. formatjet-0.1.0/src/formatjet/openapi/models/job_summary_status.py +29 -0
  109. formatjet-0.1.0/src/formatjet/openapi/models/list_formats_response_200.py +84 -0
  110. formatjet-0.1.0/src/formatjet/openapi/models/list_jobs_response_200.py +95 -0
  111. formatjet-0.1.0/src/formatjet/openapi/models/list_operations_from.py +95 -0
  112. formatjet-0.1.0/src/formatjet/openapi/models/list_operations_response_200.py +82 -0
  113. formatjet-0.1.0/src/formatjet/openapi/models/list_operations_to.py +95 -0
  114. formatjet-0.1.0/src/formatjet/openapi/models/list_webhook_deliveries_response_200.py +95 -0
  115. formatjet-0.1.0/src/formatjet/openapi/models/list_webhooks_response_200.py +81 -0
  116. formatjet-0.1.0/src/formatjet/openapi/models/operation.py +148 -0
  117. formatjet-0.1.0/src/formatjet/openapi/models/operation_credits.py +69 -0
  118. formatjet-0.1.0/src/formatjet/openapi/models/operation_engines_item.py +87 -0
  119. formatjet-0.1.0/src/formatjet/openapi/models/operation_engines_item_engines_item.py +69 -0
  120. formatjet-0.1.0/src/formatjet/openapi/models/operation_files.py +70 -0
  121. formatjet-0.1.0/src/formatjet/openapi/models/operation_kind.py +16 -0
  122. formatjet-0.1.0/src/formatjet/openapi/models/operation_options_schema.py +45 -0
  123. formatjet-0.1.0/src/formatjet/openapi/models/pricing.py +153 -0
  124. formatjet-0.1.0/src/formatjet/openapi/models/pricing_credit_packs_item.py +77 -0
  125. formatjet-0.1.0/src/formatjet/openapi/models/pricing_credit_weights_item.py +85 -0
  126. formatjet-0.1.0/src/formatjet/openapi/models/pricing_plans_item.py +156 -0
  127. formatjet-0.1.0/src/formatjet/openapi/models/pricing_plans_item_overage_type_1.py +61 -0
  128. formatjet-0.1.0/src/formatjet/openapi/models/problem.py +155 -0
  129. formatjet-0.1.0/src/formatjet/openapi/models/problem_code.py +47 -0
  130. formatjet-0.1.0/src/formatjet/openapi/models/problem_errors_item.py +69 -0
  131. formatjet-0.1.0/src/formatjet/openapi/models/replay_webhook_event_body.py +45 -0
  132. formatjet-0.1.0/src/formatjet/openapi/models/upload.py +115 -0
  133. formatjet-0.1.0/src/formatjet/openapi/models/upload_headers.py +47 -0
  134. formatjet-0.1.0/src/formatjet/openapi/models/upload_method.py +15 -0
  135. formatjet-0.1.0/src/formatjet/openapi/models/upload_request.py +56 -0
  136. formatjet-0.1.0/src/formatjet/openapi/models/usage.py +93 -0
  137. formatjet-0.1.0/src/formatjet/openapi/models/usage_days_item.py +93 -0
  138. formatjet-0.1.0/src/formatjet/openapi/models/usage_totals.py +85 -0
  139. formatjet-0.1.0/src/formatjet/openapi/models/webhook_delivery.py +204 -0
  140. formatjet-0.1.0/src/formatjet/openapi/models/webhook_delivery_event_type.py +17 -0
  141. formatjet-0.1.0/src/formatjet/openapi/models/webhook_delivery_mode.py +16 -0
  142. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint.py +258 -0
  143. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_disabled_reason_type_1.py +20 -0
  144. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_disabled_reason_type_2_type_1.py +20 -0
  145. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_disabled_reason_type_3_type_1.py +20 -0
  146. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_events_item.py +17 -0
  147. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_mode.py +16 -0
  148. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_request.py +84 -0
  149. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_request_events_item.py +21 -0
  150. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_update.py +101 -0
  151. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_update_events_item.py +19 -0
  152. formatjet-0.1.0/src/formatjet/openapi/models/webhook_endpoint_with_secret.py +267 -0
  153. formatjet-0.1.0/src/formatjet/openapi/types.py +54 -0
  154. formatjet-0.1.0/src/formatjet/py.typed +0 -0
  155. formatjet-0.1.0/tests/test_client.py +384 -0
  156. formatjet-0.1.0/tests/test_version.py +19 -0
  157. formatjet-0.1.0/tests/test_webhooks.py +48 -0
@@ -0,0 +1,47 @@
1
+ # Dependencies
2
+ node_modules/
3
+
4
+ # Build output
5
+ dist/
6
+ build/
7
+ .astro/
8
+ .output/
9
+ *.tsbuildinfo
10
+
11
+ # Cloudflare / Wrangler
12
+ .wrangler/
13
+ .dev.vars
14
+ .dev.vars.*
15
+ !.dev.vars.example
16
+
17
+ # Environment files
18
+ .env
19
+ .env.*
20
+ !.env.example
21
+
22
+ # Tests
23
+ coverage/
24
+ playwright-report/
25
+ test-results/
26
+ engines/corpus/output/
27
+
28
+ # Python (engine images)
29
+ __pycache__/
30
+ *.pyc
31
+ .venv/
32
+
33
+ # Logs and OS files
34
+ *.log
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # Editor and local Claude settings
39
+ .vscode/*
40
+ !.vscode/extensions.json
41
+ .idea/
42
+ .claude/settings.local.json
43
+
44
+ # Dashboard build, copied into the site at build time
45
+ apps/web/public/app/
46
+ .ruff_cache/
47
+ *.egg-info/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Taprobane Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.5
2
+ Name: formatjet
3
+ Version: 0.1.0
4
+ Summary: Convert documents, images, data and PDFs with the FormatJet API.
5
+ Project-URL: Homepage, https://formatjet.com/api
6
+ Project-URL: Documentation, https://formatjet.com/docs
7
+ Author: Taprobane Labs
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: api,docx,file conversion,formatjet,pdf
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Office/Business
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.11
19
+ Requires-Dist: attrs>=23.1
20
+ Requires-Dist: httpx<1,>=0.27
21
+ Description-Content-Type: text/markdown
22
+
23
+ # FormatJet for Python
24
+
25
+ Convert documents, images, data and PDFs with the [FormatJet API](https://formatjet.com/docs): Word to PDF, PDF to Word, HEIC to JPG, Excel to CSV, Merge PDF and [the rest](https://formatjet.com/api).
26
+
27
+ ```sh
28
+ pip install formatjet
29
+ ```
30
+
31
+ Python 3.11 or later.
32
+
33
+ ## Convert a file
34
+
35
+ Make an API key in the [dashboard](https://formatjet.com/app/) and set `FORMATJET_API_KEY`. A test key (`fj_test_…`) converts for free with smaller limits.
36
+
37
+ ```python
38
+ from formatjet import FormatJet
39
+
40
+ formatjet = FormatJet() # reads FORMATJET_API_KEY
41
+
42
+ result = formatjet.convert("report.docx", conversion="word-to-pdf")
43
+ result.file.save("report.pdf")
44
+ ```
45
+
46
+ `convert()` sends the file in one request (up to 25 MB) and returns the converted files: `result.files` holds several for Split PDF, a PDF's pages as images or a workbook's sheets as CSV, and `file.save()` with no path writes each under its own name. Name the conversion by its slug (`GET /v1/operations` lists them), or say only the format to make: `to="pdf"`. Options go in `options`, such as `formatjet.convert("scan.pdf", conversion="pdf-to-jpg", options={"dpi": 300})`.
47
+
48
+ A file is a path, its bytes, a binary file object, or `(filename, bytes)` to name the output after the input.
49
+
50
+ ## Larger files
51
+
52
+ `upload_and_convert()` uploads the file straight to storage first, so it takes files up to your plan's limit, then makes a job, waits for it and downloads the result:
53
+
54
+ ```python
55
+ result = formatjet.upload_and_convert(
56
+ "scan.pdf",
57
+ conversion="pdf-to-word",
58
+ metadata={"order": "8812"},
59
+ on_progress=lambda job: print(job.progress),
60
+ )
61
+ ```
62
+
63
+ Files to join (Merge PDF, Image to PDF) go as a list, in order: `formatjet.convert(["first.pdf", "second.pdf"], conversion="merge-pdf")`.
64
+
65
+ ## Jobs
66
+
67
+ ```python
68
+ job = formatjet.jobs.create(
69
+ {
70
+ "input": {"url": "https://example.com/report.docx"},
71
+ "steps": [{"op": "convert", "conversion": "word-to-pdf"}],
72
+ "webhook": "https://example.com/hooks/formatjet",
73
+ }
74
+ )
75
+ done = formatjet.jobs.wait(job.id)
76
+ formatjet.download(done.outputs[0]).save()
77
+
78
+ for summary in formatjet.jobs.iterate():
79
+ print(summary.id, summary.status)
80
+ formatjet.jobs.delete(job.id) # files deleted now; returns the signed receipt
81
+ ```
82
+
83
+ `jobs.get()`, `jobs.list()`, `jobs.cancel()` and `upload()` cover the rest. Every endpoint is also in `formatjet.openapi`, generated from the OpenAPI document; pass `formatjet.api` as its client:
84
+
85
+ ```python
86
+ from formatjet.openapi.api.account import get_account
87
+
88
+ account = get_account.sync(client=formatjet.api)
89
+ ```
90
+
91
+ ## Errors and retries
92
+
93
+ Failed calls and failed jobs raise `FormatJetError`. Branch on its `code` ([the list](https://formatjet.com/docs/errors)); `request_id` identifies the request if you contact us.
94
+
95
+ ```python
96
+ from formatjet import FormatJetError
97
+
98
+ try:
99
+ formatjet.convert("report.docx", conversion="word-to-pdf")
100
+ except FormatJetError as error:
101
+ if error.code == "insufficient_credits":
102
+ ...
103
+ ```
104
+
105
+ The client retries 429s, 5xx answers and network errors twice, honouring `Retry-After`. Each POST carries an `Idempotency-Key`, the same on every retry, so a retry never makes a second job. Set `max_retries` and `timeout` in the constructor; use the client as a context manager, or call `close()`, to free its connections.
106
+
107
+ ## Webhooks
108
+
109
+ Check each delivery's signature with the raw body, before parsing it:
110
+
111
+ ```python
112
+ from formatjet import WebhookSignatureError, parse_webhook
113
+
114
+ try:
115
+ event = parse_webhook(request.body, request.headers.get("FormatJet-Signature"), secret)
116
+ except WebhookSignatureError:
117
+ return Response(status=400)
118
+ if event["type"] == "job.completed":
119
+ print(event["data"]["job"]["outputs"])
120
+ ```
121
+
122
+ `verify_webhook()` returns the result instead, with the reason when it fails.
123
+
124
+ ## Licence
125
+
126
+ MIT
@@ -0,0 +1,104 @@
1
+ # FormatJet for Python
2
+
3
+ Convert documents, images, data and PDFs with the [FormatJet API](https://formatjet.com/docs): Word to PDF, PDF to Word, HEIC to JPG, Excel to CSV, Merge PDF and [the rest](https://formatjet.com/api).
4
+
5
+ ```sh
6
+ pip install formatjet
7
+ ```
8
+
9
+ Python 3.11 or later.
10
+
11
+ ## Convert a file
12
+
13
+ Make an API key in the [dashboard](https://formatjet.com/app/) and set `FORMATJET_API_KEY`. A test key (`fj_test_…`) converts for free with smaller limits.
14
+
15
+ ```python
16
+ from formatjet import FormatJet
17
+
18
+ formatjet = FormatJet() # reads FORMATJET_API_KEY
19
+
20
+ result = formatjet.convert("report.docx", conversion="word-to-pdf")
21
+ result.file.save("report.pdf")
22
+ ```
23
+
24
+ `convert()` sends the file in one request (up to 25 MB) and returns the converted files: `result.files` holds several for Split PDF, a PDF's pages as images or a workbook's sheets as CSV, and `file.save()` with no path writes each under its own name. Name the conversion by its slug (`GET /v1/operations` lists them), or say only the format to make: `to="pdf"`. Options go in `options`, such as `formatjet.convert("scan.pdf", conversion="pdf-to-jpg", options={"dpi": 300})`.
25
+
26
+ A file is a path, its bytes, a binary file object, or `(filename, bytes)` to name the output after the input.
27
+
28
+ ## Larger files
29
+
30
+ `upload_and_convert()` uploads the file straight to storage first, so it takes files up to your plan's limit, then makes a job, waits for it and downloads the result:
31
+
32
+ ```python
33
+ result = formatjet.upload_and_convert(
34
+ "scan.pdf",
35
+ conversion="pdf-to-word",
36
+ metadata={"order": "8812"},
37
+ on_progress=lambda job: print(job.progress),
38
+ )
39
+ ```
40
+
41
+ Files to join (Merge PDF, Image to PDF) go as a list, in order: `formatjet.convert(["first.pdf", "second.pdf"], conversion="merge-pdf")`.
42
+
43
+ ## Jobs
44
+
45
+ ```python
46
+ job = formatjet.jobs.create(
47
+ {
48
+ "input": {"url": "https://example.com/report.docx"},
49
+ "steps": [{"op": "convert", "conversion": "word-to-pdf"}],
50
+ "webhook": "https://example.com/hooks/formatjet",
51
+ }
52
+ )
53
+ done = formatjet.jobs.wait(job.id)
54
+ formatjet.download(done.outputs[0]).save()
55
+
56
+ for summary in formatjet.jobs.iterate():
57
+ print(summary.id, summary.status)
58
+ formatjet.jobs.delete(job.id) # files deleted now; returns the signed receipt
59
+ ```
60
+
61
+ `jobs.get()`, `jobs.list()`, `jobs.cancel()` and `upload()` cover the rest. Every endpoint is also in `formatjet.openapi`, generated from the OpenAPI document; pass `formatjet.api` as its client:
62
+
63
+ ```python
64
+ from formatjet.openapi.api.account import get_account
65
+
66
+ account = get_account.sync(client=formatjet.api)
67
+ ```
68
+
69
+ ## Errors and retries
70
+
71
+ Failed calls and failed jobs raise `FormatJetError`. Branch on its `code` ([the list](https://formatjet.com/docs/errors)); `request_id` identifies the request if you contact us.
72
+
73
+ ```python
74
+ from formatjet import FormatJetError
75
+
76
+ try:
77
+ formatjet.convert("report.docx", conversion="word-to-pdf")
78
+ except FormatJetError as error:
79
+ if error.code == "insufficient_credits":
80
+ ...
81
+ ```
82
+
83
+ The client retries 429s, 5xx answers and network errors twice, honouring `Retry-After`. Each POST carries an `Idempotency-Key`, the same on every retry, so a retry never makes a second job. Set `max_retries` and `timeout` in the constructor; use the client as a context manager, or call `close()`, to free its connections.
84
+
85
+ ## Webhooks
86
+
87
+ Check each delivery's signature with the raw body, before parsing it:
88
+
89
+ ```python
90
+ from formatjet import WebhookSignatureError, parse_webhook
91
+
92
+ try:
93
+ event = parse_webhook(request.body, request.headers.get("FormatJet-Signature"), secret)
94
+ except WebhookSignatureError:
95
+ return Response(status=400)
96
+ if event["type"] == "job.completed":
97
+ print(event["data"]["job"]["outputs"])
98
+ ```
99
+
100
+ `verify_webhook()` returns the result instead, with the reason when it fails.
101
+
102
+ ## Licence
103
+
104
+ MIT
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "formatjet"
7
+ version = "0.1.0"
8
+ description = "Convert documents, images, data and PDFs with the FormatJet API."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Taprobane Labs" }]
13
+ requires-python = ">=3.11"
14
+ dependencies = ["httpx>=0.27,<1", "attrs>=23.1"]
15
+ keywords = ["formatjet", "file conversion", "pdf", "docx", "api"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Topic :: Office/Business",
23
+ "Typing :: Typed",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://formatjet.com/api"
28
+ Documentation = "https://formatjet.com/docs"
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/formatjet"]
32
+
33
+ [tool.hatch.build.targets.sdist]
34
+ include = ["/src", "/tests", "/README.md", "/LICENSE"]
35
+
36
+ [tool.ruff]
37
+ line-length = 120
38
+ target-version = "py311"
39
+ extend-exclude = ["src/formatjet/openapi"]
@@ -0,0 +1,53 @@
1
+ """FormatJet: convert documents, images, data and PDFs with the FormatJet API.
2
+
3
+ from formatjet import FormatJet
4
+
5
+ formatjet = FormatJet() # reads FORMATJET_API_KEY
6
+ result = formatjet.convert("report.docx", conversion="word-to-pdf")
7
+ result.file.save("report.pdf")
8
+ """
9
+
10
+ from ._client import (
11
+ DEFAULT_BASE_URL,
12
+ ConvertResult,
13
+ FileInput,
14
+ FormatJet,
15
+ JobPage,
16
+ Jobs,
17
+ OutputFile,
18
+ filename_from,
19
+ )
20
+ from ._errors import FormatJetError
21
+ from ._webhooks import (
22
+ DEFAULT_TOLERANCE_SECONDS,
23
+ SIGNATURE_HEADER,
24
+ WebhookSignatureError,
25
+ WebhookVerification,
26
+ parse_webhook,
27
+ verify_webhook,
28
+ )
29
+ from .openapi.models import Job, JobSummary, Upload
30
+
31
+ __version__ = "0.1.0"
32
+
33
+ __all__ = [
34
+ "DEFAULT_BASE_URL",
35
+ "DEFAULT_TOLERANCE_SECONDS",
36
+ "SIGNATURE_HEADER",
37
+ "ConvertResult",
38
+ "FileInput",
39
+ "FormatJet",
40
+ "FormatJetError",
41
+ "Job",
42
+ "JobPage",
43
+ "JobSummary",
44
+ "Jobs",
45
+ "OutputFile",
46
+ "Upload",
47
+ "WebhookSignatureError",
48
+ "WebhookVerification",
49
+ "__version__",
50
+ "filename_from",
51
+ "parse_webhook",
52
+ "verify_webhook",
53
+ ]