django-converter-studio 1.0.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.
- django_converter_studio-1.0.0/.gitignore +13 -0
- django_converter_studio-1.0.0/CHANGELOG.md +22 -0
- django_converter_studio-1.0.0/LICENSE +21 -0
- django_converter_studio-1.0.0/PKG-INFO +383 -0
- django_converter_studio-1.0.0/README.md +338 -0
- django_converter_studio-1.0.0/pyproject.toml +138 -0
- django_converter_studio-1.0.0/src/django_converter_studio/__init__.py +35 -0
- django_converter_studio-1.0.0/src/django_converter_studio/_version.py +3 -0
- django_converter_studio-1.0.0/src/django_converter_studio/admin.py +173 -0
- django_converter_studio-1.0.0/src/django_converter_studio/apps.py +17 -0
- django_converter_studio-1.0.0/src/django_converter_studio/checks.py +169 -0
- django_converter_studio-1.0.0/src/django_converter_studio/client.py +58 -0
- django_converter_studio-1.0.0/src/django_converter_studio/conf.py +116 -0
- django_converter_studio-1.0.0/src/django_converter_studio/formats.py +49 -0
- django_converter_studio-1.0.0/src/django_converter_studio/jobs.py +489 -0
- django_converter_studio-1.0.0/src/django_converter_studio/management/__init__.py +0 -0
- django_converter_studio-1.0.0/src/django_converter_studio/management/commands/__init__.py +0 -0
- django_converter_studio-1.0.0/src/django_converter_studio/management/commands/converter_studio_account.py +24 -0
- django_converter_studio-1.0.0/src/django_converter_studio/management/commands/converter_studio_convert.py +96 -0
- django_converter_studio-1.0.0/src/django_converter_studio/migrations/0001_initial.py +97 -0
- django_converter_studio-1.0.0/src/django_converter_studio/migrations/__init__.py +0 -0
- django_converter_studio-1.0.0/src/django_converter_studio/models.py +72 -0
- django_converter_studio-1.0.0/src/django_converter_studio/py.typed +0 -0
- django_converter_studio-1.0.0/src/django_converter_studio/reports.py +60 -0
- django_converter_studio-1.0.0/src/django_converter_studio/rules.py +152 -0
- django_converter_studio-1.0.0/src/django_converter_studio/services.py +221 -0
- django_converter_studio-1.0.0/src/django_converter_studio/signals.py +64 -0
- django_converter_studio-1.0.0/src/django_converter_studio/tasks.py +123 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/__init__.py +25 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/apps.py +26 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/checks.py +103 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/forms.py +92 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/receivers.py +43 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/rules.py +42 -0
- django_converter_studio-1.0.0/src/django_converter_studio/wagtail/wagtail_hooks.py +155 -0
- django_converter_studio-1.0.0/tests/__init__.py +0 -0
- django_converter_studio-1.0.0/tests/conftest.py +54 -0
- django_converter_studio-1.0.0/tests/fake_api.py +211 -0
- django_converter_studio-1.0.0/tests/settings.py +95 -0
- django_converter_studio-1.0.0/tests/test_admin.py +104 -0
- django_converter_studio-1.0.0/tests/test_checks.py +93 -0
- django_converter_studio-1.0.0/tests/test_commands.py +82 -0
- django_converter_studio-1.0.0/tests/test_jobs.py +307 -0
- django_converter_studio-1.0.0/tests/test_rules.py +55 -0
- django_converter_studio-1.0.0/tests/test_services.py +150 -0
- django_converter_studio-1.0.0/tests/test_tasks.py +127 -0
- django_converter_studio-1.0.0/tests/test_wagtail.py +209 -0
- django_converter_studio-1.0.0/tests/testapp/__init__.py +0 -0
- django_converter_studio-1.0.0/tests/testapp/admin.py +27 -0
- django_converter_studio-1.0.0/tests/testapp/apps.py +16 -0
- django_converter_studio-1.0.0/tests/testapp/migrations/0001_initial.py +74 -0
- django_converter_studio-1.0.0/tests/testapp/migrations/__init__.py +0 -0
- django_converter_studio-1.0.0/tests/testapp/models.py +68 -0
- django_converter_studio-1.0.0/tests/urls.py +19 -0
- django_converter_studio-1.0.0/tox.ini +64 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this package are listed here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package uses
|
|
5
|
+
[semantic versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## 1.0.0 - 2026-11-23
|
|
8
|
+
|
|
9
|
+
The first release, for Django 5.2, 6.0 and 6.1 and Wagtail 7.4, 8.0 and 8.1.
|
|
10
|
+
|
|
11
|
+
- Rules on models (`converter_studio_rules`, `register()`): replace an uploaded file in place,
|
|
12
|
+
save the result into another file field, or its text into a text field; run inline after the
|
|
13
|
+
save is committed or through Django's tasks framework (Django 6.0+ or the `django-tasks`
|
|
14
|
+
backport); files read and written through any storage.
|
|
15
|
+
- The conversions log in the admin, with "Convert again" and "Approve the price and convert"; the
|
|
16
|
+
"Convert with Converter Studio" admin action (also on the object's page on Django 6.1).
|
|
17
|
+
- The `converter_studio_convert` management command for files already stored, the
|
|
18
|
+
`converter_studio_account` command, and system checks for the settings and the rules.
|
|
19
|
+
- `convert()`, `convert_to_storage()`, `extract_text()` and `open_client()` for your own code, and
|
|
20
|
+
the `file_converted` signal.
|
|
21
|
+
- Wagtail: images in formats Wagtail cannot open (HEIC, camera RAW, EPS, AI) converted while they
|
|
22
|
+
upload, documents converted after they are saved, bulk actions on both listings.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Converter Studio
|
|
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,383 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: django-converter-studio
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Convert uploaded files in Django and Wagtail with Converter Studio: HEIC and RAW photos to JPG, Office documents to PDF, scans to text, videos to MP4.
|
|
5
|
+
Project-URL: Homepage, https://converter.studio
|
|
6
|
+
Project-URL: Documentation, https://converter.studio/developers
|
|
7
|
+
Project-URL: Source, https://github.com/tariksucu/django-converter-studio
|
|
8
|
+
Project-URL: Issues, https://github.com/tariksucu/django-converter-studio/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/tariksucu/django-converter-studio/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Converter Studio <support@converter.studio>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: converter-studio,django,file-conversion,heic-to-jpg,ocr,pdf,raw,uploads,video,wagtail
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Environment :: Web Environment
|
|
16
|
+
Classifier: Framework :: Django
|
|
17
|
+
Classifier: Framework :: Django :: 5.2
|
|
18
|
+
Classifier: Framework :: Django :: 6.0
|
|
19
|
+
Classifier: Framework :: Django :: 6.1
|
|
20
|
+
Classifier: Framework :: Wagtail
|
|
21
|
+
Classifier: Framework :: Wagtail :: 7
|
|
22
|
+
Classifier: Framework :: Wagtail :: 8
|
|
23
|
+
Classifier: Intended Audience :: Developers
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Classifier: Programming Language :: Python :: 3
|
|
26
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
32
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
33
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
|
34
|
+
Classifier: Topic :: Multimedia :: Video :: Conversion
|
|
35
|
+
Classifier: Topic :: Office/Business
|
|
36
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
37
|
+
Classifier: Typing :: Typed
|
|
38
|
+
Requires-Python: >=3.11
|
|
39
|
+
Requires-Dist: converter-studio<2,>=1.0
|
|
40
|
+
Requires-Dist: django>=5.2
|
|
41
|
+
Requires-Dist: httpx<1,>=0.27
|
|
42
|
+
Provides-Extra: wagtail
|
|
43
|
+
Requires-Dist: wagtail>=7.4; extra == 'wagtail'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# Converter Studio for Django and Wagtail
|
|
47
|
+
|
|
48
|
+
Convert uploaded files in Django and Wagtail with [Converter Studio](https://converter.studio):
|
|
49
|
+
iPhone photos (HEIC) and camera RAW photos become JPG, Office documents get a PDF, scans and
|
|
50
|
+
pictures give their text to a text field (OCR), videos become MP4. The conversion runs on
|
|
51
|
+
Converter Studio's servers, so there is nothing to install on yours: no ImageMagick, no FFmpeg, no
|
|
52
|
+
LibreOffice, no Tesseract.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from django.db import models
|
|
56
|
+
from django_converter_studio import ConverterStudioMixin, Rule, formats
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class Photo(ConverterStudioMixin, models.Model):
|
|
60
|
+
image = models.FileField(upload_to="photos/")
|
|
61
|
+
|
|
62
|
+
converter_studio_rules = [
|
|
63
|
+
Rule(field="image", sources=formats.HEIC + formats.RAW, to="jpg"),
|
|
64
|
+
]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Upload `IMG_1234.HEIC` (in the admin, a form or your own code) and the object is saved with
|
|
68
|
+
`photos/IMG_1234.jpg`.
|
|
69
|
+
|
|
70
|
+
- **Rules** on your models: replace a file in place, write the result into another file field, or
|
|
71
|
+
the result's text into a text field.
|
|
72
|
+
- Runs **inline** right after the save is committed, or in the background through **Django's
|
|
73
|
+
tasks framework** (Django 6.0+, or the `django-tasks` backport on Django 5.2).
|
|
74
|
+
- Works with **any storage**: files are read and written through the field's `Storage` (the file
|
|
75
|
+
system, S3, Google Cloud, Azure...).
|
|
76
|
+
- An admin action **"Convert with Converter Studio"**, a **conversions log** in the admin with the
|
|
77
|
+
cost and the API's reason for every failure, a **management command** for files already
|
|
78
|
+
stored, and **system checks** for the settings and the rules.
|
|
79
|
+
- **Wagtail**: images Wagtail cannot open (HEIC, camera RAW, EPS and AI artwork) are converted
|
|
80
|
+
while they upload, documents can become PDF, and both listings get a bulk action.
|
|
81
|
+
- Built on the official Python client,
|
|
82
|
+
[converter-studio](https://github.com/tariksucu/converter-studio-python).
|
|
83
|
+
|
|
84
|
+
## Requirements
|
|
85
|
+
|
|
86
|
+
- Python 3.11 or later.
|
|
87
|
+
- Django 5.2 (LTS), 6.0 or 6.1.
|
|
88
|
+
- Wagtail 7.4 (LTS), 8.0 or 8.1, for the Wagtail part (optional).
|
|
89
|
+
- A Converter Studio account and an API key. Free accounts get credits every day; most photos
|
|
90
|
+
and documents cost 1 credit, reading the text of a picture (OCR) a little more; audio and video
|
|
91
|
+
are priced by their length (video also by its frame size and the format made). See
|
|
92
|
+
[pricing](https://converter.studio/pricing).
|
|
93
|
+
|
|
94
|
+
## Installation
|
|
95
|
+
|
|
96
|
+
```console
|
|
97
|
+
$ pip install django-converter-studio # Django
|
|
98
|
+
$ pip install "django-converter-studio[wagtail]" # Django and Wagtail
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
# settings.py
|
|
103
|
+
INSTALLED_APPS = [
|
|
104
|
+
# ...
|
|
105
|
+
"django_converter_studio",
|
|
106
|
+
]
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```console
|
|
110
|
+
$ python manage.py migrate # the conversions log
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Create an API key on your [account page](https://converter.studio/account#api-keys) (keys start
|
|
114
|
+
with `cvs_live_`; keep them secret) and put it in the environment of your web server and workers:
|
|
115
|
+
|
|
116
|
+
```console
|
|
117
|
+
$ export CONVERTER_STUDIO_API_KEY=cvs_live_...
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Or set `CONVERTER_STUDIO_API_KEY` in your settings, read from wherever you keep secrets.
|
|
121
|
+
`python manage.py converter_studio_account` checks the key and shows the plan and the credits
|
|
122
|
+
left; `python manage.py check` tells you when something is not set up right.
|
|
123
|
+
|
|
124
|
+
## Rules
|
|
125
|
+
|
|
126
|
+
A rule converts the files of one `FileField` (or `ImageField`) whose extension is in `sources` to
|
|
127
|
+
the format `to`. Give a model a `converter_studio_rules` list (the `ConverterStudioMixin` adds
|
|
128
|
+
`convert_files()` and declares the attribute), or register rules for a model you do not own from
|
|
129
|
+
your `AppConfig.ready()`:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from django_converter_studio import Rule, formats, register
|
|
133
|
+
|
|
134
|
+
register(Document, Rule(field="file", sources=formats.OFFICE, to="pdf", target="pdf"))
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Where the result goes:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
class Report(ConverterStudioMixin, models.Model):
|
|
141
|
+
file = models.FileField(upload_to="reports/")
|
|
142
|
+
pdf = models.FileField(upload_to="reports/pdf/", blank=True)
|
|
143
|
+
text = models.TextField(blank=True)
|
|
144
|
+
|
|
145
|
+
converter_studio_rules = [
|
|
146
|
+
# Office documents get a PDF next to them, in another file field.
|
|
147
|
+
Rule(field="file", sources=formats.OFFICE, to="pdf", target="pdf"),
|
|
148
|
+
# Pictures and scanned PDFs give their text to a text field (OCR).
|
|
149
|
+
Rule(
|
|
150
|
+
field="file",
|
|
151
|
+
sources=(*formats.OCR_IMAGES, "pdf"),
|
|
152
|
+
to="txt",
|
|
153
|
+
target="text",
|
|
154
|
+
options={"ocr": True},
|
|
155
|
+
),
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class Clip(ConverterStudioMixin, models.Model):
|
|
160
|
+
video = models.FileField(upload_to="clips/")
|
|
161
|
+
|
|
162
|
+
converter_studio_rules = [
|
|
163
|
+
# Replaced in place (no target): talk.mov becomes talk.mp4, at most 720p.
|
|
164
|
+
Rule(field="video", sources=formats.VIDEO, to="mp4", options={"height": "720"}, run="task"),
|
|
165
|
+
]
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| `Rule(...)` | What it does |
|
|
169
|
+
| ----------------- | ------------------------------------------------------------------------------------------ |
|
|
170
|
+
| `field` | the file field whose files are converted |
|
|
171
|
+
| `sources` | the extensions converted (`formats.HEIC`, `RAW`, `OFFICE`, `VIDEO`, `AUDIO`, `OCR_IMAGES`) |
|
|
172
|
+
| `to` | the format made: `jpg`, `png`, `webp`, `pdf`, `txt`, `docx`, `mp4`, `mp3`... |
|
|
173
|
+
| `target` | none: replace the file in place; a file field: save the result there; a text field: text |
|
|
174
|
+
| `options` | the API's conversion settings, such as `{"quality": "high"}` or `{"height": "720"}` |
|
|
175
|
+
| `max_credits` | the most one file may cost to start on its own (`CONVERTER_STUDIO_MAX_CREDITS`, 20) |
|
|
176
|
+
| `run` | `"inline"` or `"task"` (`CONVERTER_STUDIO_RUN`) |
|
|
177
|
+
| `delete_original` | delete a replaced original from storage (`CONVERTER_STUDIO_DELETE_ORIGINALS`, off) |
|
|
178
|
+
| `name` | how the rule is shown in the conversions log (made up when not given) |
|
|
179
|
+
|
|
180
|
+
The settings each conversion takes are listed on the [API page](https://converter.studio/developers).
|
|
181
|
+
A replaced file keeps the directory its field's `upload_to` gives it, and the storage picks a free
|
|
182
|
+
name (`IMG_1234.jpg`, then `IMG_1234_a8Kd0Ze.jpg`). Django never deletes replaced files on its
|
|
183
|
+
own, and neither does this package unless you ask it to. `ImageField` width and height fields
|
|
184
|
+
follow the new file.
|
|
185
|
+
|
|
186
|
+
### When files are converted
|
|
187
|
+
|
|
188
|
+
A file is converted when it is **new**: an upload, or a `File` assigned in code, saved with the
|
|
189
|
+
object. Saving an object without changing its file does nothing, and so does loading fixtures. A
|
|
190
|
+
conversion runs **after the save is committed**, never inside your transaction:
|
|
191
|
+
|
|
192
|
+
- `run="inline"`: in the same process, before the request that saved the object ends (the admin
|
|
193
|
+
shows the converted file right away). Fine for photos and documents, which take a second or two.
|
|
194
|
+
- `run="task"`: queued with Django's tasks framework and run by your worker. Use it for videos.
|
|
195
|
+
Django 6.0 and later have the framework built in; on Django 5.2 install the backport,
|
|
196
|
+
[`django-tasks`](https://pypi.org/project/django-tasks/) (Wagtail installs it already). Django
|
|
197
|
+
itself ships only an immediate backend, which runs the task at once; for real background work
|
|
198
|
+
configure a backend with a worker, for example
|
|
199
|
+
[`django-tasks-db`](https://pypi.org/project/django-tasks-db/):
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
INSTALLED_APPS += ["django_tasks_db"]
|
|
203
|
+
TASKS = {"default": {"BACKEND": "django_tasks_db.DatabaseBackend", "QUEUES": ["default"]}}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
```console
|
|
207
|
+
$ python manage.py db_worker
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- `CONVERTER_STUDIO_RUN = "auto"` (the default): tasks when a tasks framework is there,
|
|
211
|
+
otherwise inline. Without a framework, `"task"` runs inline too (`manage.py check` says so).
|
|
212
|
+
|
|
213
|
+
A conversion that fails never breaks the save: the original stays, and the conversions log says
|
|
214
|
+
why. The instance you saved follows an inline conversion; one done by a task is in the database,
|
|
215
|
+
so call `refresh_from_db()` to see it.
|
|
216
|
+
|
|
217
|
+
### The admin
|
|
218
|
+
|
|
219
|
+
- **Admin › Converter Studio › Conversions** lists every conversion: the file, the object, its
|
|
220
|
+
status, what it cost, and for a failure the API's own reason ("This API key does not work.",
|
|
221
|
+
"You have used today's credits."...). "Convert again" runs failed ones again; "Approve the price
|
|
222
|
+
and convert" goes ahead with those that cost more than `max_credits` (nothing is charged before
|
|
223
|
+
that).
|
|
224
|
+
- **"Convert with Converter Studio"** converts the selected objects' files by their rules, for
|
|
225
|
+
files stored before the rules existed. Add it with the mixin, or name it in `actions`:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from django_converter_studio.admin import ConverterStudioAdminMixin, convert_with_converter_studio
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@admin.register(Photo)
|
|
232
|
+
class PhotoAdmin(ConverterStudioAdminMixin, admin.ModelAdmin): ...
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@admin.register(Report)
|
|
236
|
+
class ReportAdmin(admin.ModelAdmin):
|
|
237
|
+
actions = [convert_with_converter_studio]
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
On Django 6.1 the action is offered on each object's own page too.
|
|
241
|
+
|
|
242
|
+
### Management commands
|
|
243
|
+
|
|
244
|
+
```console
|
|
245
|
+
$ python manage.py converter_studio_convert --dry-run # what would be converted
|
|
246
|
+
$ python manage.py converter_studio_convert # every model with rules
|
|
247
|
+
$ python manage.py converter_studio_convert library.Photo --limit 100
|
|
248
|
+
$ python manage.py converter_studio_convert library.Report --field file --force --queue
|
|
249
|
+
$ python manage.py converter_studio_account # the key, the plan, the credits
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Files converted already are skipped: a replaced file no longer has a source extension, and a
|
|
253
|
+
filled target is left alone unless `--force`. `--queue` hands the conversions to the tasks
|
|
254
|
+
framework instead of converting them one after the other. The command ends with an error when a
|
|
255
|
+
conversion failed.
|
|
256
|
+
|
|
257
|
+
### In your own code
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
from django_converter_studio import convert, convert_to_storage, extract_text, open_client
|
|
261
|
+
|
|
262
|
+
with convert(photo.image, "webp", options={"quality": "balanced"}) as result:
|
|
263
|
+
photo.preview.save(result.name, result.file) # result.file is a Django File
|
|
264
|
+
|
|
265
|
+
name = convert_to_storage(report.file, "pdf") # saved next to it, through its storage
|
|
266
|
+
text = extract_text(scan.file) # OCR for pictures and scanned PDFs
|
|
267
|
+
|
|
268
|
+
with open_client() as client: # the converter-studio client, configured
|
|
269
|
+
print(client.account().credits)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`convert()` takes a `FieldFile` (read through its storage), an upload, any Django `File`, a path,
|
|
273
|
+
or bytes with `file_name=`. Errors are the client's exceptions (`ConversionFailedError`,
|
|
274
|
+
`AuthenticationError`, `InsufficientCreditsError`, `ConfirmationRequiredError`...), whose message
|
|
275
|
+
is the API's own sentence, meant for people. `obj.convert_files()` converts one object by its rules.
|
|
276
|
+
|
|
277
|
+
`django_converter_studio.signals.file_converted` is sent after a converted file is saved (`sender`
|
|
278
|
+
is the model, with `instance`, `rule`, `job`, `original_name` and `name`), for example to clear a
|
|
279
|
+
cache.
|
|
280
|
+
|
|
281
|
+
## Wagtail
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
# settings.py
|
|
285
|
+
from django_converter_studio import formats
|
|
286
|
+
|
|
287
|
+
INSTALLED_APPS = [
|
|
288
|
+
# ...
|
|
289
|
+
"django_converter_studio",
|
|
290
|
+
"django_converter_studio.wagtail",
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
WAGTAILIMAGES_IMAGE_FORM_BASE = "django_converter_studio.wagtail.forms.ConvertingImageForm"
|
|
294
|
+
WAGTAILIMAGES_EXTENSIONS = [
|
|
295
|
+
"avif",
|
|
296
|
+
"gif",
|
|
297
|
+
"jpg",
|
|
298
|
+
"jpeg",
|
|
299
|
+
"png",
|
|
300
|
+
"webp",
|
|
301
|
+
*formats.HEIC,
|
|
302
|
+
*formats.RAW,
|
|
303
|
+
*formats.VECTOR,
|
|
304
|
+
]
|
|
305
|
+
WAGTAILIMAGES_MAX_UPLOAD_SIZE = 50 * 1024 * 1024 # RAW photos are large
|
|
306
|
+
|
|
307
|
+
# Optional: Office documents become PDF after they upload.
|
|
308
|
+
CONVERTER_STUDIO_WAGTAIL_DOCUMENTS = {"docx": "pdf", "doc": "pdf", "odt": "pdf", "pptx": "pdf"}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
- **Images** are converted while they upload, before Wagtail checks them, in every upload path of
|
|
312
|
+
the admin ("Add an image", "Add images", the image chooser, replacing a file): HEIC and HEIF
|
|
313
|
+
photos and camera RAW photos (CR2, NEF, ARW, DNG) become JPG, EPS and AI artwork becomes PNG.
|
|
314
|
+
Wagtail stores the converted image, with its real size, and makes its renditions from it.
|
|
315
|
+
`CONVERTER_STUDIO_WAGTAIL_IMAGES` changes the list (`{"heic": "webp", ...}`).
|
|
316
|
+
- If an image cannot be converted (no credits, a damaged file...), the upload is refused with
|
|
317
|
+
Converter Studio's reason, unless Wagtail can use the original as it is (a HEIC, when Wagtail
|
|
318
|
+
reads HEIC): then the original is kept, and the conversions log says why it was not converted.
|
|
319
|
+
- **Documents** in `CONVERTER_STUDIO_WAGTAIL_DOCUMENTS` are converted after they are saved, in
|
|
320
|
+
place: the document keeps its title, collection, tags and links, and Wagtail's file size and
|
|
321
|
+
hash follow the new file.
|
|
322
|
+
- The image and document listings get a **"Convert with Converter Studio"** bulk action, for files
|
|
323
|
+
uploaded before.
|
|
324
|
+
- The conversions log is in Django's admin (at `/django-admin/` in a project made with
|
|
325
|
+
`wagtail start`).
|
|
326
|
+
- `CONVERTER_STUDIO_WAGTAIL_OPTIONS` gives conversion settings per format made, for example
|
|
327
|
+
`{"jpg": {"quality": "high", "keepMetadata": True}}`.
|
|
328
|
+
- `WAGTAILIMAGES_EXTENSIONS` must list the extensions to convert, or Wagtail's uploader refuses
|
|
329
|
+
them before the form sees them; `manage.py check` warns about a missing one.
|
|
330
|
+
- The "Add an image" file dialog offers the extensions to convert. The "Add images" page's dialog
|
|
331
|
+
filters on images, which on some systems hides EPS and AI files: drag them onto the page, or
|
|
332
|
+
choose "All files" in the dialog.
|
|
333
|
+
- With your own image base form, add the mixin:
|
|
334
|
+
`class MyImageForm(ConvertingImageFormMixin, BaseImageForm)`.
|
|
335
|
+
|
|
336
|
+
Photoshop files (PSD) are not converted: Converter Studio does not read them.
|
|
337
|
+
|
|
338
|
+
## Settings
|
|
339
|
+
|
|
340
|
+
| Setting | Default | What it does |
|
|
341
|
+
| -------------------------------------------- | ------------------------------ | ----------------------------------------------------------- |
|
|
342
|
+
| `CONVERTER_STUDIO_API_KEY` | the environment variable | your API key |
|
|
343
|
+
| `CONVERTER_STUDIO_BASE_URL` | `https://converter.studio/api` | the API's address |
|
|
344
|
+
| `CONVERTER_STUDIO_MAX_CREDITS` | `20` | the most one file may cost to start without your approval |
|
|
345
|
+
| `CONVERTER_STUDIO_TIMEOUT` | `600` | seconds a conversion may take (rules, commands, actions) |
|
|
346
|
+
| `CONVERTER_STUDIO_UPLOAD_TIMEOUT` | `60` | seconds a Wagtail image upload waits for its conversion |
|
|
347
|
+
| `CONVERTER_STUDIO_RUN` | `"auto"` | `"auto"`, `"inline"` or `"task"` |
|
|
348
|
+
| `CONVERTER_STUDIO_TASK_BACKEND`, `..._QUEUE` | `"default"` | the `TASKS` backend and queue conversions are enqueued on |
|
|
349
|
+
| `CONVERTER_STUDIO_DELETE_ORIGINALS` | `False` | delete a replaced original from storage |
|
|
350
|
+
| `CONVERTER_STUDIO_WAGTAIL_IMAGES` | HEIC, RAW → JPG; EPS, AI → PNG | what each image extension becomes while it uploads |
|
|
351
|
+
| `CONVERTER_STUDIO_WAGTAIL_DOCUMENTS` | `{}` | what each document extension becomes after it is saved |
|
|
352
|
+
| `CONVERTER_STUDIO_WAGTAIL_OPTIONS` | `{}` | conversion settings by the format made, for Wagtail's files |
|
|
353
|
+
|
|
354
|
+
## Limits
|
|
355
|
+
|
|
356
|
+
- The largest file depends on your plan; files over 95 MB are uploaded in parts on their own.
|
|
357
|
+
Audio and video length depends on the plan too.
|
|
358
|
+
- One file in, one file out: no merging or splitting of PDFs.
|
|
359
|
+
- An inline conversion keeps its request waiting; use tasks for videos and large files.
|
|
360
|
+
- A conversion that costs more than `max_credits` waits for your approval in the conversions log.
|
|
361
|
+
|
|
362
|
+
## Privacy
|
|
363
|
+
|
|
364
|
+
The files your rules match are sent to Converter Studio (converter.studio) to be converted, with
|
|
365
|
+
their names; nothing else about your site or its users is sent. Uploaded files are deleted as
|
|
366
|
+
soon as they are converted, and results 6 hours later. Each request also says which integration
|
|
367
|
+
sent it (`X-Converter-Studio-Client: django/<version>`), for usage statistics only. Mention
|
|
368
|
+
Converter Studio in your site's privacy policy if your users' files are converted. See the
|
|
369
|
+
[privacy policy](https://converter.studio/privacy) and the [terms](https://converter.studio/terms).
|
|
370
|
+
|
|
371
|
+
The API key is sent only to the API's address, never logged and never shown in the admin.
|
|
372
|
+
|
|
373
|
+
## Links
|
|
374
|
+
|
|
375
|
+
- Converter Studio: <https://converter.studio>
|
|
376
|
+
- API documentation: <https://converter.studio/developers>
|
|
377
|
+
- Pricing: <https://converter.studio/pricing>
|
|
378
|
+
- Source code and issues: <https://github.com/tariksucu/django-converter-studio>
|
|
379
|
+
- Changelog: <https://github.com/tariksucu/django-converter-studio/blob/main/CHANGELOG.md>
|
|
380
|
+
- The Python client: <https://github.com/tariksucu/converter-studio-python>
|
|
381
|
+
- Support: <support@converter.studio>
|
|
382
|
+
|
|
383
|
+
MIT licensed. © Converter Studio.
|