Skip to content

Commit 2c561e2

Browse files
feat: introduce 0.15.x support
1 parent 3f57ce2 commit 2c561e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1539
-1314
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Appwrite Python SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-python.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-0.14.0-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-0.15.0-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

9-
**This SDK is compatible with Appwrite server version 0.14.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-python/releases).**
9+
**This SDK is compatible with Appwrite server version 0.15.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-python/releases).**
1010

1111
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Python SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1212

appwrite/client.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def __init__(self):
1111
self._endpoint = 'https://HOSTNAME/v1'
1212
self._global_headers = {
1313
'content-type': '',
14-
'x-sdk-version': 'appwrite:python:0.9.0',
15-
'X-Appwrite-Response-Format' : '0.14.0',
14+
'x-sdk-version': 'appwrite:python:0.10.0',
15+
'X-Appwrite-Response-Format' : '0.15.0',
1616
}
1717

1818
def set_self_signed(self, status=True):
@@ -76,7 +76,7 @@ def call(self, method, path='', headers=None, params=None):
7676
stringify = True
7777
for key in data.copy():
7878
if isinstance(data[key], InputFile):
79-
files[key] = (data[key].name, data[key].file)
79+
files[key] = (data[key].filename, data[key].data)
8080
del data[key]
8181
response = None
8282
try:
@@ -118,21 +118,27 @@ def chunked_upload(
118118
on_progress = None,
119119
upload_id = ''
120120
):
121-
file_path = str(params[param_name])
122-
file_name = os.path.basename(file_path)
123-
size = os.stat(file_path).st_size
121+
input_file = params[param_name]
122+
123+
if input_file.source_type == 'path':
124+
size = os.stat(input_file.path).st_size
125+
input = open(input_file.path, 'rb')
126+
elif input_file.source_type == 'bytes':
127+
size = len(input_file.data)
128+
input = input_file.data
124129

125130
if size < self._chunk_size:
126-
slice = open(file_path, 'rb').read()
127-
params[param_name] = InputFile(file_path, file_name, slice)
131+
if input_file.source_type == 'path':
132+
input_file.data = input.read()
133+
134+
params[param_name] = input_file
128135
return self.call(
129136
'post',
130137
path,
131138
headers,
132139
params
133140
)
134141

135-
input = open(file_path, 'rb')
136142
offset = 0
137143
counter = 0
138144

@@ -148,9 +154,16 @@ def chunked_upload(
148154
input.seek(offset)
149155

150156
while offset < size:
151-
slice = input.read(self._chunk_size) or input.read(size - offset)
157+
if input_file.source_type == 'path':
158+
input_file.data = input.read(self._chunk_size) or input.read(size - offset)
159+
elif input_file.source_type == 'bytes':
160+
if offset + self._chunk_size < size:
161+
end = offset + self._chunk_size
162+
else:
163+
end = size - offset
164+
input_file.data = input[offset:end]
152165

153-
params[param_name] = InputFile(file_path, file_name, slice)
166+
params[param_name] = input_file
154167
headers["content-range"] = f'bytes {offset}-{min((offset + self._chunk_size) - 1, size)}/{size}'
155168

156169
result = self.call(

appwrite/input_file.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
import os
2+
import mimetypes
3+
14
class InputFile:
2-
def __init__(self, path, name, file):
3-
self.path = path
4-
self.name = name
5-
self.file = file
5+
@classmethod
6+
def from_path(cls, path):
7+
instance = cls()
8+
instance.path = path
9+
instance.filename = os.path.basename(path)
10+
instance.mime_type = mimetypes.guess_type(path)
11+
instance.source_type = 'path'
12+
return instance
13+
14+
@classmethod
15+
def from_bytes(cls, bytes, filename = None, mime_type = None):
16+
instance = cls()
17+
instance.data = bytes
18+
instance.filename = filename
19+
instance.mime_type = mime_type
20+
instance.source_type = 'bytes'
21+
return instance

0 commit comments

Comments
 (0)