django-capo-s3 0.0.1__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.
Potentially problematic release.
This version of django-capo-s3 might be problematic. Click here for more details.
- django_capo_s3-0.0.1/.gitignore +218 -0
- django_capo_s3-0.0.1/LICENSE +21 -0
- django_capo_s3-0.0.1/PKG-INFO +213 -0
- django_capo_s3-0.0.1/README.md +183 -0
- django_capo_s3-0.0.1/pyproject.toml +111 -0
- django_capo_s3-0.0.1/src/django_capo_s3/__init__.py +22 -0
- django_capo_s3-0.0.1/src/django_capo_s3/cloudfront.py +35 -0
- django_capo_s3-0.0.1/src/django_capo_s3/core.py +157 -0
- django_capo_s3-0.0.1/src/django_capo_s3/files.py +71 -0
- django_capo_s3-0.0.1/src/django_capo_s3/proxy.py +31 -0
- django_capo_s3-0.0.1/src/django_capo_s3/py.typed +0 -0
- django_capo_s3-0.0.1/src/django_capo_s3/static.py +44 -0
- django_capo_s3-0.0.1/src/django_capo_s3/storage.py +282 -0
- django_capo_s3-0.0.1/src/django_capo_s3/transfer.py +91 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dmitrii Anfimov
|
|
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,213 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: django-capo-s3
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Support for S3 storage backend in Django
|
|
5
|
+
Project-URL: Documentation, https://github.com/danfimov/django-capo-s3
|
|
6
|
+
Project-URL: Repository, https://github.com/danfimov/django-capo-s3
|
|
7
|
+
Project-URL: Changelog, https://github.com/danfimov/django-capo-s3/releases
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Framework :: Django
|
|
12
|
+
Classifier: Framework :: Django :: 5.2
|
|
13
|
+
Classifier: Framework :: Django :: 6.0
|
|
14
|
+
Classifier: Framework :: Django :: 6.1
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: capo-s3>=0.11.0
|
|
27
|
+
Requires-Dist: cryptography>=50.0.0
|
|
28
|
+
Requires-Dist: django>=5.2
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# django-capo-s3
|
|
32
|
+
|
|
33
|
+
A Django file storage backend for S3-compatible object stores, built on the [capo-s3](https://pypi.org/project/capo-s3/)
|
|
34
|
+
client instead of boto3 — a drop-in alternative to `django-storages[s3]`.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- **Media and static storages** — `S3Storage` for media, plus `S3StaticStorage` (plain) and `S3ManifestStaticStorage`
|
|
39
|
+
(content-hashed names + `staticfiles.json` manifest for cache-busting) for `collectstatic`. The manifest can live in
|
|
40
|
+
the bucket or in a separate storage.
|
|
41
|
+
- **URLs** — presigned URLs by default (with per-call `expire` and response overrides like `response_content_disposition`),
|
|
42
|
+
unsigned public URLs, or CloudFront-signed URLs for a custom domain.
|
|
43
|
+
- **Uploads** — streaming single-`PUT` uploads that automatically switch to a concurrent multipart transfer above a
|
|
44
|
+
configurable threshold.
|
|
45
|
+
- **Transparent gzip** — eligible content types are stored compressed and decompressed on read.
|
|
46
|
+
- **Server-side encryption, storage class, cache-control, metadata, ...** — via `object_parameters`, passed straight
|
|
47
|
+
through to the underlying request.
|
|
48
|
+
- **Flexible networking options** — custom endpoint (e.g. MinIO), path- or virtual-host addressing, TLS verification and
|
|
49
|
+
custom CA bundles, connection timeouts, pool size, HTTP/HTTPS/SOCKS5 proxies, and retry attempts.
|
|
50
|
+
- **Fully typed** — this is already the bare minimum for new packages.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
uv add django-capo-s3 # or: pip install django-capo-s3
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
Register the backend in Django's `STORAGES` setting; everything under `OPTIONS` is passed to the backend:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
STORAGES = {
|
|
64
|
+
"default": {
|
|
65
|
+
"BACKEND": "django_capo_s3.S3Storage",
|
|
66
|
+
"OPTIONS": {
|
|
67
|
+
"bucket": "my-bucket",
|
|
68
|
+
"region": "eu-central-1",
|
|
69
|
+
"location": "media",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
"staticfiles": {
|
|
73
|
+
"BACKEND": "django_capo_s3.S3ManifestStaticStorage",
|
|
74
|
+
"OPTIONS": {"bucket": "my-bucket", "location": "static"},
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
### On a model field
|
|
82
|
+
|
|
83
|
+
Most apps never touch storage directly. With `STORAGES["default"]` configured (above), `FileField` /
|
|
84
|
+
`ImageField` just work — uploads, `.url`, `.size`, and `.open()` all go through the backend.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from django.db import models
|
|
88
|
+
|
|
89
|
+
class Report(models.Model):
|
|
90
|
+
csv = models.FileField(upload_to="reports/")
|
|
91
|
+
|
|
92
|
+
report = Report.objects.create(csv=uploaded_file)
|
|
93
|
+
report.csv.url # presigned URL to the object
|
|
94
|
+
report.csv.size # size in bytes
|
|
95
|
+
report.csv.open().read() # file contents
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Direct storage access
|
|
99
|
+
|
|
100
|
+
Grab the configured default storage from the registry and use the `Storage` API directly.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from django.core.files.base import ContentFile
|
|
104
|
+
from django.core.files.storage import storages
|
|
105
|
+
|
|
106
|
+
storage = storages["default"]
|
|
107
|
+
name = storage.save("reports/june.csv", ContentFile(b"col1,col2\n")) # returns the stored name
|
|
108
|
+
storage.exists(name) # True
|
|
109
|
+
storage.size(name) # size in bytes
|
|
110
|
+
with storage.open(name) as f:
|
|
111
|
+
data = f.read()
|
|
112
|
+
storage.delete(name) # no error if it's already gone
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Download URLs
|
|
116
|
+
|
|
117
|
+
`url()` is presigned by default. Override the lifetime per call, or add response headers — for example, to
|
|
118
|
+
force a browser "Save as" with a filename.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
storage.url("reports/june.csv") # presigned, default lifetime (url_expire)
|
|
122
|
+
storage.url("reports/june.csv", expire=60) # presigned, valid for 60 seconds
|
|
123
|
+
storage.url(
|
|
124
|
+
"reports/june.csv",
|
|
125
|
+
parameters={"response_content_disposition": 'attachment; filename="june.csv"'},
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For a public bucket, set `"querystring_auth": False` in `OPTIONS` to get plain, cacheable URLs instead.
|
|
130
|
+
|
|
131
|
+
### Static files with cache-busting
|
|
132
|
+
|
|
133
|
+
Point `STORAGES["staticfiles"]` at `S3ManifestStaticStorage`. `collectstatic` then stores each file under a
|
|
134
|
+
content-hashed name and `{% static %}` resolves through the manifest, so assets can be served with
|
|
135
|
+
long-lived caching. Keep the manifest local so web workers don't fetch it from S3 on startup.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from django.core.files.storage import FileSystemStorage
|
|
139
|
+
|
|
140
|
+
STORAGES["staticfiles"] = {
|
|
141
|
+
"BACKEND": "django_capo_s3.S3ManifestStaticStorage",
|
|
142
|
+
"OPTIONS": {
|
|
143
|
+
"bucket": "my-bucket",
|
|
144
|
+
"location": "static",
|
|
145
|
+
"manifest_storage": FileSystemStorage(location=BASE_DIR / ".static-manifest"),
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Serving through a CDN (CloudFront)
|
|
151
|
+
|
|
152
|
+
Set `custom_domain` for plain CDN URLs, or add a CloudFront key pair to sign them for a private
|
|
153
|
+
distribution.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
"OPTIONS": {
|
|
157
|
+
"bucket": "my-bucket",
|
|
158
|
+
"custom_domain": "d123.cloudfront.net",
|
|
159
|
+
"cloudfront_key": cloudfront_private_key_pem, # PEM contents
|
|
160
|
+
"cloudfront_key_id": "K1ABCDEF",
|
|
161
|
+
"url_expire": 300,
|
|
162
|
+
}
|
|
163
|
+
# storage.url(name) -> https://d123.cloudfront.net/...?Expires=...&Signature=...&Key-Pair-Id=...
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Large uploads and gzip
|
|
167
|
+
|
|
168
|
+
Uploads switch to a concurrent multipart transfer above `multipart_threshold`; text assets can be stored
|
|
169
|
+
gzip-compressed and are transparently decompressed on read.
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
"OPTIONS": {
|
|
173
|
+
"bucket": "my-bucket",
|
|
174
|
+
"multipart_threshold": 32 * 1024 * 1024, # start multipart at 32 MiB
|
|
175
|
+
"multipart_chunksize": 16 * 1024 * 1024,
|
|
176
|
+
"multipart_concurrency": 8, # parts uploaded in parallel
|
|
177
|
+
"gzip": True, # compress CSS/JS/JSON/... at rest
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Encryption, storage class, and other object metadata
|
|
182
|
+
|
|
183
|
+
Whatever `object_parameters` contains is passed straight to each upload — e.g. SSE-KMS plus a storage class
|
|
184
|
+
and cache header.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
"OPTIONS": {
|
|
188
|
+
"bucket": "my-bucket",
|
|
189
|
+
"default_acl": "private",
|
|
190
|
+
"object_parameters": {
|
|
191
|
+
"server_side_encryption": "aws:kms",
|
|
192
|
+
"ssekms_key_id": "arn:aws:kms:eu-central-1:123456789012:key/abcd-...",
|
|
193
|
+
"storage_class": "STANDARD_IA",
|
|
194
|
+
"cache_control": "max-age=86400",
|
|
195
|
+
},
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Networking (endpoint tuning, proxies)
|
|
200
|
+
|
|
201
|
+
Tune timeouts, the connection pool, retries, TLS verification, and proxies as needed.
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
"OPTIONS": {
|
|
205
|
+
"bucket": "my-bucket",
|
|
206
|
+
"connect_timeout": 5.0,
|
|
207
|
+
"read_timeout": 30.0,
|
|
208
|
+
"max_connections_per_host": 50,
|
|
209
|
+
"retry_max_attempts": 5,
|
|
210
|
+
"verify": "/etc/ssl/certs/internal-ca.pem", # or False to disable TLS verification
|
|
211
|
+
"proxies": {"https": "http://proxy.internal:8080"},
|
|
212
|
+
}
|
|
213
|
+
```
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# django-capo-s3
|
|
2
|
+
|
|
3
|
+
A Django file storage backend for S3-compatible object stores, built on the [capo-s3](https://pypi.org/project/capo-s3/)
|
|
4
|
+
client instead of boto3 — a drop-in alternative to `django-storages[s3]`.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **Media and static storages** — `S3Storage` for media, plus `S3StaticStorage` (plain) and `S3ManifestStaticStorage`
|
|
9
|
+
(content-hashed names + `staticfiles.json` manifest for cache-busting) for `collectstatic`. The manifest can live in
|
|
10
|
+
the bucket or in a separate storage.
|
|
11
|
+
- **URLs** — presigned URLs by default (with per-call `expire` and response overrides like `response_content_disposition`),
|
|
12
|
+
unsigned public URLs, or CloudFront-signed URLs for a custom domain.
|
|
13
|
+
- **Uploads** — streaming single-`PUT` uploads that automatically switch to a concurrent multipart transfer above a
|
|
14
|
+
configurable threshold.
|
|
15
|
+
- **Transparent gzip** — eligible content types are stored compressed and decompressed on read.
|
|
16
|
+
- **Server-side encryption, storage class, cache-control, metadata, ...** — via `object_parameters`, passed straight
|
|
17
|
+
through to the underlying request.
|
|
18
|
+
- **Flexible networking options** — custom endpoint (e.g. MinIO), path- or virtual-host addressing, TLS verification and
|
|
19
|
+
custom CA bundles, connection timeouts, pool size, HTTP/HTTPS/SOCKS5 proxies, and retry attempts.
|
|
20
|
+
- **Fully typed** — this is already the bare minimum for new packages.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
uv add django-capo-s3 # or: pip install django-capo-s3
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
Register the backend in Django's `STORAGES` setting; everything under `OPTIONS` is passed to the backend:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
STORAGES = {
|
|
34
|
+
"default": {
|
|
35
|
+
"BACKEND": "django_capo_s3.S3Storage",
|
|
36
|
+
"OPTIONS": {
|
|
37
|
+
"bucket": "my-bucket",
|
|
38
|
+
"region": "eu-central-1",
|
|
39
|
+
"location": "media",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
"staticfiles": {
|
|
43
|
+
"BACKEND": "django_capo_s3.S3ManifestStaticStorage",
|
|
44
|
+
"OPTIONS": {"bucket": "my-bucket", "location": "static"},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### On a model field
|
|
52
|
+
|
|
53
|
+
Most apps never touch storage directly. With `STORAGES["default"]` configured (above), `FileField` /
|
|
54
|
+
`ImageField` just work — uploads, `.url`, `.size`, and `.open()` all go through the backend.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from django.db import models
|
|
58
|
+
|
|
59
|
+
class Report(models.Model):
|
|
60
|
+
csv = models.FileField(upload_to="reports/")
|
|
61
|
+
|
|
62
|
+
report = Report.objects.create(csv=uploaded_file)
|
|
63
|
+
report.csv.url # presigned URL to the object
|
|
64
|
+
report.csv.size # size in bytes
|
|
65
|
+
report.csv.open().read() # file contents
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Direct storage access
|
|
69
|
+
|
|
70
|
+
Grab the configured default storage from the registry and use the `Storage` API directly.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from django.core.files.base import ContentFile
|
|
74
|
+
from django.core.files.storage import storages
|
|
75
|
+
|
|
76
|
+
storage = storages["default"]
|
|
77
|
+
name = storage.save("reports/june.csv", ContentFile(b"col1,col2\n")) # returns the stored name
|
|
78
|
+
storage.exists(name) # True
|
|
79
|
+
storage.size(name) # size in bytes
|
|
80
|
+
with storage.open(name) as f:
|
|
81
|
+
data = f.read()
|
|
82
|
+
storage.delete(name) # no error if it's already gone
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Download URLs
|
|
86
|
+
|
|
87
|
+
`url()` is presigned by default. Override the lifetime per call, or add response headers — for example, to
|
|
88
|
+
force a browser "Save as" with a filename.
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
storage.url("reports/june.csv") # presigned, default lifetime (url_expire)
|
|
92
|
+
storage.url("reports/june.csv", expire=60) # presigned, valid for 60 seconds
|
|
93
|
+
storage.url(
|
|
94
|
+
"reports/june.csv",
|
|
95
|
+
parameters={"response_content_disposition": 'attachment; filename="june.csv"'},
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
For a public bucket, set `"querystring_auth": False` in `OPTIONS` to get plain, cacheable URLs instead.
|
|
100
|
+
|
|
101
|
+
### Static files with cache-busting
|
|
102
|
+
|
|
103
|
+
Point `STORAGES["staticfiles"]` at `S3ManifestStaticStorage`. `collectstatic` then stores each file under a
|
|
104
|
+
content-hashed name and `{% static %}` resolves through the manifest, so assets can be served with
|
|
105
|
+
long-lived caching. Keep the manifest local so web workers don't fetch it from S3 on startup.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from django.core.files.storage import FileSystemStorage
|
|
109
|
+
|
|
110
|
+
STORAGES["staticfiles"] = {
|
|
111
|
+
"BACKEND": "django_capo_s3.S3ManifestStaticStorage",
|
|
112
|
+
"OPTIONS": {
|
|
113
|
+
"bucket": "my-bucket",
|
|
114
|
+
"location": "static",
|
|
115
|
+
"manifest_storage": FileSystemStorage(location=BASE_DIR / ".static-manifest"),
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Serving through a CDN (CloudFront)
|
|
121
|
+
|
|
122
|
+
Set `custom_domain` for plain CDN URLs, or add a CloudFront key pair to sign them for a private
|
|
123
|
+
distribution.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
"OPTIONS": {
|
|
127
|
+
"bucket": "my-bucket",
|
|
128
|
+
"custom_domain": "d123.cloudfront.net",
|
|
129
|
+
"cloudfront_key": cloudfront_private_key_pem, # PEM contents
|
|
130
|
+
"cloudfront_key_id": "K1ABCDEF",
|
|
131
|
+
"url_expire": 300,
|
|
132
|
+
}
|
|
133
|
+
# storage.url(name) -> https://d123.cloudfront.net/...?Expires=...&Signature=...&Key-Pair-Id=...
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Large uploads and gzip
|
|
137
|
+
|
|
138
|
+
Uploads switch to a concurrent multipart transfer above `multipart_threshold`; text assets can be stored
|
|
139
|
+
gzip-compressed and are transparently decompressed on read.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
"OPTIONS": {
|
|
143
|
+
"bucket": "my-bucket",
|
|
144
|
+
"multipart_threshold": 32 * 1024 * 1024, # start multipart at 32 MiB
|
|
145
|
+
"multipart_chunksize": 16 * 1024 * 1024,
|
|
146
|
+
"multipart_concurrency": 8, # parts uploaded in parallel
|
|
147
|
+
"gzip": True, # compress CSS/JS/JSON/... at rest
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Encryption, storage class, and other object metadata
|
|
152
|
+
|
|
153
|
+
Whatever `object_parameters` contains is passed straight to each upload — e.g. SSE-KMS plus a storage class
|
|
154
|
+
and cache header.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
"OPTIONS": {
|
|
158
|
+
"bucket": "my-bucket",
|
|
159
|
+
"default_acl": "private",
|
|
160
|
+
"object_parameters": {
|
|
161
|
+
"server_side_encryption": "aws:kms",
|
|
162
|
+
"ssekms_key_id": "arn:aws:kms:eu-central-1:123456789012:key/abcd-...",
|
|
163
|
+
"storage_class": "STANDARD_IA",
|
|
164
|
+
"cache_control": "max-age=86400",
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Networking (endpoint tuning, proxies)
|
|
170
|
+
|
|
171
|
+
Tune timeouts, the connection pool, retries, TLS verification, and proxies as needed.
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
"OPTIONS": {
|
|
175
|
+
"bucket": "my-bucket",
|
|
176
|
+
"connect_timeout": 5.0,
|
|
177
|
+
"read_timeout": 30.0,
|
|
178
|
+
"max_connections_per_host": 50,
|
|
179
|
+
"retry_max_attempts": 5,
|
|
180
|
+
"verify": "/etc/ssl/certs/internal-ca.pem", # or False to disable TLS verification
|
|
181
|
+
"proxies": {"https": "http://proxy.internal:8080"},
|
|
182
|
+
}
|
|
183
|
+
```
|