nerdstack-ark 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.
- nerdstack_ark-1.0.0/.gitignore +18 -0
- nerdstack_ark-1.0.0/LICENSE +21 -0
- nerdstack_ark-1.0.0/PKG-INFO +187 -0
- nerdstack_ark-1.0.0/README.md +144 -0
- nerdstack_ark-1.0.0/examples/django/apps.py +13 -0
- nerdstack_ark-1.0.0/examples/django/views.py +16 -0
- nerdstack_ark-1.0.0/examples/fastapi/app.py +28 -0
- nerdstack_ark-1.0.0/examples/flask/app.py +27 -0
- nerdstack_ark-1.0.0/pyproject.toml +69 -0
- nerdstack_ark-1.0.0/src/ark_py/__init__.py +31 -0
- nerdstack_ark-1.0.0/src/ark_py/_shared.py +182 -0
- nerdstack_ark-1.0.0/src/ark_py/async_client.py +543 -0
- nerdstack_ark-1.0.0/src/ark_py/errors.py +76 -0
- nerdstack_ark-1.0.0/src/ark_py/models.py +108 -0
- nerdstack_ark-1.0.0/src/ark_py/py.typed +1 -0
- nerdstack_ark-1.0.0/src/ark_py/s3.py +38 -0
- nerdstack_ark-1.0.0/src/ark_py/sync.py +381 -0
- nerdstack_ark-1.0.0/tests/conftest.py +24 -0
- nerdstack_ark-1.0.0/tests/test_async.py +171 -0
- nerdstack_ark-1.0.0/tests/test_sync.py +239 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
*.tgz
|
|
4
|
+
*.log
|
|
5
|
+
.DS_Store
|
|
6
|
+
.env
|
|
7
|
+
.env.local
|
|
8
|
+
.venv/
|
|
9
|
+
packages/ark-py/.venv/
|
|
10
|
+
packages/ark-py/.mypy_cache/
|
|
11
|
+
packages/ark-py/.pytest_cache/
|
|
12
|
+
packages/ark-py/.ruff_cache/
|
|
13
|
+
packages/ark-py/build/
|
|
14
|
+
packages/ark-py/dist/
|
|
15
|
+
packages/ark-py/*.egg-info/
|
|
16
|
+
packages/ark-py/src/*.egg-info/
|
|
17
|
+
__pycache__/
|
|
18
|
+
*.py[cod]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nerdstack
|
|
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,187 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nerdstack-ark
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for Ark storage, with sync, async, and S3-compatible access.
|
|
5
|
+
Project-URL: Homepage, https://ark.nerdstackgrp.com
|
|
6
|
+
Project-URL: Documentation, https://github.com/joshhumphrey02/ark-sdk/tree/master/packages/ark-py#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/joshhumphrey02/ark-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/joshhumphrey02/ark-sdk/issues
|
|
9
|
+
Author: Nerdstack
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ark,django,fastapi,flask,s3,storage,upload
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Framework :: FastAPI
|
|
17
|
+
Classifier: Framework :: Flask
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
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: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: httpx<1,>=0.27
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
29
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
33
|
+
Requires-Dist: twine>=6.0; extra == 'dev'
|
|
34
|
+
Provides-Extra: django
|
|
35
|
+
Requires-Dist: django>=4.2; extra == 'django'
|
|
36
|
+
Provides-Extra: fastapi
|
|
37
|
+
Requires-Dist: fastapi>=0.110; extra == 'fastapi'
|
|
38
|
+
Provides-Extra: flask
|
|
39
|
+
Requires-Dist: flask>=2.3; extra == 'flask'
|
|
40
|
+
Provides-Extra: s3
|
|
41
|
+
Requires-Dist: boto3<2,>=1.35; extra == 's3'
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# Ark for Python
|
|
45
|
+
|
|
46
|
+
The official Python SDK for [Ark](https://ark.nerdstackgrp.com) storage. It is
|
|
47
|
+
framework-independent and provides:
|
|
48
|
+
|
|
49
|
+
- `Ark` for Django, Flask, Celery, scripts, and synchronous workers.
|
|
50
|
+
- `AsyncArk` for FastAPI, Starlette, aiohttp, and async workers.
|
|
51
|
+
- Memory-bounded single and multipart uploads.
|
|
52
|
+
- Typed result models and one normalized `ArkError` exception.
|
|
53
|
+
- Optional access through Ark's S3-compatible endpoint using boto3.
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install nerdstack-ark
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For S3-compatible access:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install "nerdstack-ark[s3]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Python 3.10 or newer is required.
|
|
68
|
+
|
|
69
|
+
## Synchronous usage
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import os
|
|
73
|
+
from ark_py import Ark
|
|
74
|
+
|
|
75
|
+
with Ark(os.environ["ARK_API_TOKEN"]) as ark:
|
|
76
|
+
folder = ark.folders.create("Product Media")
|
|
77
|
+
file = ark.files.upload(
|
|
78
|
+
"./hero.mp4",
|
|
79
|
+
folder_id=folder.id,
|
|
80
|
+
content_type="video/mp4",
|
|
81
|
+
)
|
|
82
|
+
download_url = ark.files.get_download_url(file.id, expires_in_seconds=600)
|
|
83
|
+
print(download_url)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Filesystem paths stream directly from disk. A file-like object is also
|
|
87
|
+
accepted; provide `size` and `filename` when it is not seekable:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
file = ark.files.upload(
|
|
91
|
+
request.stream,
|
|
92
|
+
size=int(request.headers["content-length"]),
|
|
93
|
+
filename="upload.bin",
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The stream must produce exactly the declared number of bytes. Ark aborts an
|
|
98
|
+
incomplete server-side session if the transfer fails, underflows, or overflows.
|
|
99
|
+
|
|
100
|
+
## Asynchronous usage
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import os
|
|
104
|
+
from ark_py import AsyncArk
|
|
105
|
+
|
|
106
|
+
async with AsyncArk(os.environ["ARK_API_TOKEN"]) as ark:
|
|
107
|
+
file = await ark.files.upload("./hero.mp4", content_type="video/mp4")
|
|
108
|
+
usage = await ark.usage()
|
|
109
|
+
print(file.id, usage.storage.used_bytes)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`AsyncArk.files.upload` accepts paths, ordinary binary files, and
|
|
113
|
+
`AsyncIterable[bytes]`. Async iterables require an exact `size` and `filename`.
|
|
114
|
+
|
|
115
|
+
## Files, folders, images, and sessions
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
page = ark.files.list(folder_id=folder.id, limit=50)
|
|
119
|
+
file = ark.files.get(page.data[0].id)
|
|
120
|
+
ark.files.move(file.id, folder_id=None)
|
|
121
|
+
ark.files.delete(file.id)
|
|
122
|
+
|
|
123
|
+
folders = ark.folders.list(parent_id=None)
|
|
124
|
+
ark.folders.rename(folder.id, "Campaign Media")
|
|
125
|
+
|
|
126
|
+
image_url = ark.images.url(file.id)
|
|
127
|
+
signed_url = ark.images.signed_url(file.id, expires_in_seconds=600)
|
|
128
|
+
|
|
129
|
+
session = ark.create_client_session(ttl_seconds=900)
|
|
130
|
+
# Hand session.token to @nerdstackgrp/ark-client in the browser.
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## S3-compatible access
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import os
|
|
137
|
+
from ark_py import create_s3_client
|
|
138
|
+
|
|
139
|
+
s3 = create_s3_client(
|
|
140
|
+
access_key_id=os.environ["ARK_ACCESS_KEY_ID"],
|
|
141
|
+
secret_access_key=os.environ["ARK_SECRET_ACCESS_KEY"],
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
s3.put_object(Bucket="product-media", Key="hero.jpg", Body=image_bytes)
|
|
145
|
+
objects = s3.list_objects_v2(Bucket="product-media", Prefix="photos/")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
These must be Ark-issued S3 credentials. The helper configures SigV4 and
|
|
149
|
+
path-style addressing for `https://ark.nerdstackgrp.com/s3`.
|
|
150
|
+
|
|
151
|
+
## Errors
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from ark_py import ArkError
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
ark.files.get("missing")
|
|
158
|
+
except ArkError as error:
|
|
159
|
+
print(error.code, error.status, error.request_id, error.retryable)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Framework examples
|
|
163
|
+
|
|
164
|
+
Complete examples live in [`examples/`](examples):
|
|
165
|
+
|
|
166
|
+
- Django upload view and application lifecycle.
|
|
167
|
+
- Flask application factory and upload route.
|
|
168
|
+
- FastAPI lifespan management and `UploadFile` streaming.
|
|
169
|
+
|
|
170
|
+
Keep `ARK_API_TOKEN` in server-side environment configuration. Never expose it
|
|
171
|
+
to templates, frontend bundles, mobile apps, logs, or error responses.
|
|
172
|
+
|
|
173
|
+
## Development
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
python -m venv .venv
|
|
177
|
+
.venv/bin/pip install -e ".[dev]"
|
|
178
|
+
.venv/bin/pytest
|
|
179
|
+
.venv/bin/ruff check .
|
|
180
|
+
.venv/bin/mypy
|
|
181
|
+
.venv/bin/python -m build
|
|
182
|
+
.venv/bin/twine check dist/*
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT © Nerdstack.
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Ark for Python
|
|
2
|
+
|
|
3
|
+
The official Python SDK for [Ark](https://ark.nerdstackgrp.com) storage. It is
|
|
4
|
+
framework-independent and provides:
|
|
5
|
+
|
|
6
|
+
- `Ark` for Django, Flask, Celery, scripts, and synchronous workers.
|
|
7
|
+
- `AsyncArk` for FastAPI, Starlette, aiohttp, and async workers.
|
|
8
|
+
- Memory-bounded single and multipart uploads.
|
|
9
|
+
- Typed result models and one normalized `ArkError` exception.
|
|
10
|
+
- Optional access through Ark's S3-compatible endpoint using boto3.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install nerdstack-ark
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For S3-compatible access:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install "nerdstack-ark[s3]"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Python 3.10 or newer is required.
|
|
25
|
+
|
|
26
|
+
## Synchronous usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import os
|
|
30
|
+
from ark_py import Ark
|
|
31
|
+
|
|
32
|
+
with Ark(os.environ["ARK_API_TOKEN"]) as ark:
|
|
33
|
+
folder = ark.folders.create("Product Media")
|
|
34
|
+
file = ark.files.upload(
|
|
35
|
+
"./hero.mp4",
|
|
36
|
+
folder_id=folder.id,
|
|
37
|
+
content_type="video/mp4",
|
|
38
|
+
)
|
|
39
|
+
download_url = ark.files.get_download_url(file.id, expires_in_seconds=600)
|
|
40
|
+
print(download_url)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Filesystem paths stream directly from disk. A file-like object is also
|
|
44
|
+
accepted; provide `size` and `filename` when it is not seekable:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
file = ark.files.upload(
|
|
48
|
+
request.stream,
|
|
49
|
+
size=int(request.headers["content-length"]),
|
|
50
|
+
filename="upload.bin",
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The stream must produce exactly the declared number of bytes. Ark aborts an
|
|
55
|
+
incomplete server-side session if the transfer fails, underflows, or overflows.
|
|
56
|
+
|
|
57
|
+
## Asynchronous usage
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import os
|
|
61
|
+
from ark_py import AsyncArk
|
|
62
|
+
|
|
63
|
+
async with AsyncArk(os.environ["ARK_API_TOKEN"]) as ark:
|
|
64
|
+
file = await ark.files.upload("./hero.mp4", content_type="video/mp4")
|
|
65
|
+
usage = await ark.usage()
|
|
66
|
+
print(file.id, usage.storage.used_bytes)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`AsyncArk.files.upload` accepts paths, ordinary binary files, and
|
|
70
|
+
`AsyncIterable[bytes]`. Async iterables require an exact `size` and `filename`.
|
|
71
|
+
|
|
72
|
+
## Files, folders, images, and sessions
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
page = ark.files.list(folder_id=folder.id, limit=50)
|
|
76
|
+
file = ark.files.get(page.data[0].id)
|
|
77
|
+
ark.files.move(file.id, folder_id=None)
|
|
78
|
+
ark.files.delete(file.id)
|
|
79
|
+
|
|
80
|
+
folders = ark.folders.list(parent_id=None)
|
|
81
|
+
ark.folders.rename(folder.id, "Campaign Media")
|
|
82
|
+
|
|
83
|
+
image_url = ark.images.url(file.id)
|
|
84
|
+
signed_url = ark.images.signed_url(file.id, expires_in_seconds=600)
|
|
85
|
+
|
|
86
|
+
session = ark.create_client_session(ttl_seconds=900)
|
|
87
|
+
# Hand session.token to @nerdstackgrp/ark-client in the browser.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## S3-compatible access
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import os
|
|
94
|
+
from ark_py import create_s3_client
|
|
95
|
+
|
|
96
|
+
s3 = create_s3_client(
|
|
97
|
+
access_key_id=os.environ["ARK_ACCESS_KEY_ID"],
|
|
98
|
+
secret_access_key=os.environ["ARK_SECRET_ACCESS_KEY"],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
s3.put_object(Bucket="product-media", Key="hero.jpg", Body=image_bytes)
|
|
102
|
+
objects = s3.list_objects_v2(Bucket="product-media", Prefix="photos/")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
These must be Ark-issued S3 credentials. The helper configures SigV4 and
|
|
106
|
+
path-style addressing for `https://ark.nerdstackgrp.com/s3`.
|
|
107
|
+
|
|
108
|
+
## Errors
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from ark_py import ArkError
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
ark.files.get("missing")
|
|
115
|
+
except ArkError as error:
|
|
116
|
+
print(error.code, error.status, error.request_id, error.retryable)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Framework examples
|
|
120
|
+
|
|
121
|
+
Complete examples live in [`examples/`](examples):
|
|
122
|
+
|
|
123
|
+
- Django upload view and application lifecycle.
|
|
124
|
+
- Flask application factory and upload route.
|
|
125
|
+
- FastAPI lifespan management and `UploadFile` streaming.
|
|
126
|
+
|
|
127
|
+
Keep `ARK_API_TOKEN` in server-side environment configuration. Never expose it
|
|
128
|
+
to templates, frontend bundles, mobile apps, logs, or error responses.
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
python -m venv .venv
|
|
134
|
+
.venv/bin/pip install -e ".[dev]"
|
|
135
|
+
.venv/bin/pytest
|
|
136
|
+
.venv/bin/ruff check .
|
|
137
|
+
.venv/bin/mypy
|
|
138
|
+
.venv/bin/python -m build
|
|
139
|
+
.venv/bin/twine check dist/*
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT © Nerdstack.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from django.apps import AppConfig
|
|
2
|
+
from django.conf import settings
|
|
3
|
+
|
|
4
|
+
from ark_py import Ark
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MediaConfig(AppConfig):
|
|
8
|
+
name = "media"
|
|
9
|
+
|
|
10
|
+
def ready(self) -> None:
|
|
11
|
+
# A long-lived httpx connection pool is safe to share between requests.
|
|
12
|
+
# Close it from your process shutdown hook when your server provides one.
|
|
13
|
+
self.ark = Ark(settings.ARK_API_TOKEN)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from django.apps import apps
|
|
2
|
+
from django.http import JsonResponse
|
|
3
|
+
from django.views.decorators.http import require_POST
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@require_POST
|
|
7
|
+
def upload(request):
|
|
8
|
+
uploaded = request.FILES["file"]
|
|
9
|
+
ark = apps.get_app_config("media").ark
|
|
10
|
+
file = ark.files.upload(
|
|
11
|
+
uploaded.file,
|
|
12
|
+
size=uploaded.size,
|
|
13
|
+
filename=uploaded.name,
|
|
14
|
+
content_type=uploaded.content_type,
|
|
15
|
+
)
|
|
16
|
+
return JsonResponse({"id": file.id, "url": file.url}, status=201)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from contextlib import asynccontextmanager
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
from fastapi import FastAPI, File, Request, UploadFile
|
|
6
|
+
|
|
7
|
+
from ark_py import AsyncArk
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@asynccontextmanager
|
|
11
|
+
async def lifespan(app: FastAPI):
|
|
12
|
+
async with AsyncArk(os.environ["ARK_API_TOKEN"]) as ark:
|
|
13
|
+
app.state.ark = ark
|
|
14
|
+
yield
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
app = FastAPI(lifespan=lifespan)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@app.post("/uploads", status_code=201)
|
|
21
|
+
async def upload(request: Request, incoming: Annotated[UploadFile, File()]):
|
|
22
|
+
# SpooledTemporaryFile is seekable, so the SDK infers its remaining size.
|
|
23
|
+
file = await request.app.state.ark.files.upload(
|
|
24
|
+
incoming.file,
|
|
25
|
+
filename=incoming.filename or "upload",
|
|
26
|
+
content_type=incoming.content_type,
|
|
27
|
+
)
|
|
28
|
+
return {"id": file.id, "url": file.url}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from flask import Flask, current_app, jsonify, request
|
|
4
|
+
|
|
5
|
+
from ark_py import Ark
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def create_app() -> Flask:
|
|
9
|
+
app = Flask(__name__)
|
|
10
|
+
app.extensions["ark"] = Ark(os.environ["ARK_API_TOKEN"])
|
|
11
|
+
|
|
12
|
+
@app.post("/uploads")
|
|
13
|
+
def upload():
|
|
14
|
+
incoming = request.files["file"]
|
|
15
|
+
incoming.stream.seek(0, 2)
|
|
16
|
+
size = incoming.stream.tell()
|
|
17
|
+
incoming.stream.seek(0)
|
|
18
|
+
ark = current_app.extensions["ark"]
|
|
19
|
+
file = ark.files.upload(
|
|
20
|
+
incoming.stream,
|
|
21
|
+
size=size,
|
|
22
|
+
filename=incoming.filename or "upload",
|
|
23
|
+
content_type=incoming.mimetype,
|
|
24
|
+
)
|
|
25
|
+
return jsonify(id=file.id, url=file.url), 201
|
|
26
|
+
|
|
27
|
+
return app
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nerdstack-ark"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Official Python SDK for Ark storage, with sync, async, and S3-compatible access."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "Nerdstack" }]
|
|
13
|
+
keywords = ["ark", "storage", "upload", "s3", "django", "flask", "fastapi"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 5 - Production/Stable",
|
|
16
|
+
"Framework :: AsyncIO",
|
|
17
|
+
"Framework :: Django",
|
|
18
|
+
"Framework :: FastAPI",
|
|
19
|
+
"Framework :: Flask",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
dependencies = ["httpx>=0.27,<1"]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
s3 = ["boto3>=1.35,<2"]
|
|
32
|
+
django = ["Django>=4.2"]
|
|
33
|
+
flask = ["Flask>=2.3"]
|
|
34
|
+
fastapi = ["fastapi>=0.110"]
|
|
35
|
+
dev = [
|
|
36
|
+
"build>=1.2",
|
|
37
|
+
"mypy>=1.11",
|
|
38
|
+
"pytest>=8.3",
|
|
39
|
+
"pytest-asyncio>=0.24",
|
|
40
|
+
"ruff>=0.9",
|
|
41
|
+
"twine>=6.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://ark.nerdstackgrp.com"
|
|
46
|
+
Documentation = "https://github.com/joshhumphrey02/ark-sdk/tree/master/packages/ark-py#readme"
|
|
47
|
+
Repository = "https://github.com/joshhumphrey02/ark-sdk"
|
|
48
|
+
Issues = "https://github.com/joshhumphrey02/ark-sdk/issues"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/ark_py"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
addopts = "-q"
|
|
55
|
+
asyncio_mode = "auto"
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 100
|
|
60
|
+
target-version = "py310"
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
|
|
64
|
+
|
|
65
|
+
[tool.mypy]
|
|
66
|
+
python_version = "3.10"
|
|
67
|
+
strict = true
|
|
68
|
+
packages = ["ark_py"]
|
|
69
|
+
mypy_path = "src"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Official Python SDK for Ark storage."""
|
|
2
|
+
|
|
3
|
+
from .async_client import AsyncArk
|
|
4
|
+
from .errors import ArkError
|
|
5
|
+
from .models import (
|
|
6
|
+
ArkFile,
|
|
7
|
+
ArkFolder,
|
|
8
|
+
ArkUsage,
|
|
9
|
+
ClientSession,
|
|
10
|
+
FilePage,
|
|
11
|
+
ImageOptions,
|
|
12
|
+
StorageUsage,
|
|
13
|
+
)
|
|
14
|
+
from .s3 import create_s3_client
|
|
15
|
+
from .sync import Ark
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Ark",
|
|
19
|
+
"ArkError",
|
|
20
|
+
"ArkFile",
|
|
21
|
+
"ArkFolder",
|
|
22
|
+
"ArkUsage",
|
|
23
|
+
"AsyncArk",
|
|
24
|
+
"ClientSession",
|
|
25
|
+
"FilePage",
|
|
26
|
+
"ImageOptions",
|
|
27
|
+
"StorageUsage",
|
|
28
|
+
"create_s3_client",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
__version__ = "1.0.0"
|