Skip to content

Commit ef0c3cf

Browse files
author
Bartek Kwiecien
committed
Merge branch 'release/3.0.0'
2 parents 0a0b6e5 + 7a7b5f7 commit ef0c3cf

Some content is hidden

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

75 files changed

+1948
-2005
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ tests/data/test_download.jpg
88
.coverage
99
.idea
1010
.venv
11+
12+
docs/build/*

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
dist: xenial
12
language: python
23

34
python:
4-
- "2.7"
5-
- "3.4"
65
- "3.5"
76
- "3.6"
7+
- "3.7"
8+
- "3.8-dev"
89

910
install:
1011
- pip install -r requirements.txt

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Filestack-Python Changelog
22

3+
### 3.0.0 (July 16th, 2019)
4+
- Dropped support for Python 2.7
5+
- client.upload() now handles local files and file-like objects, accepts keyword arguments only
6+
- client.upload_url() handles external url uploads
7+
- Please see [API Reference](https://filestack-python.readthedocs.io) to learn more
8+
39
### 2.8.1 (July 3th, 2019)
410
- Fixed store params in external url upload
511

README.md

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
<a href="http://travis-ci.org/filestack/filestack-python">
55
<img src="https://img.shields.io/travis/filestack/filestack-python.svg">
66
</a>
7-
<a href="https://pypi.python.org/pypi/filestack-python/2.3.1">
7+
<a href="https://pypi.python.org/pypi/filestack-python">
88
<img src="https://img.shields.io/pypi/v/filestack-python.svg">
99
</a>
10+
<img src="https://img.shields.io/pypi/pyversions/filestack-python.svg">
1011
</p>
1112
This is the official Python SDK for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
1213

1314
## Resources
1415

15-
* [API Reference](https://filestack.github.io/filestack-python)
16+
To learn more about this SDK, please visit our API Reference
17+
18+
* [API Reference](https://filestack-python.readthedocs.io)
1619

1720
## Installing
1821

@@ -28,49 +31,53 @@ or directly from GitHub
2831
pip install git+https://github.com/filestack/filestack-python.git
2932
```
3033

31-
## Usage
34+
## Quickstart
3235

3336
The Filestack SDK allows you to upload and handle filelinks using two main classes: Client and Filelink.
3437

35-
### Uploading New File with Client
38+
### Uploading files with `filestack.Client`
3639
``` python
3740
from filestack import Client
38-
client = Client("<YOUR_API_KEY>")
41+
client = Client('<YOUR_API_KEY>')
3942

40-
params = {'mimetype': 'image/png'}
41-
new_filelink = client.upload(filepath="path/to/file", params=params)
43+
new_filelink = client.upload(filepath='path/to/file')
4244
print(new_filelink.url)
4345
```
44-
Uploading local files will use Filestack's multipart upload by default. To disable, just set the argument to false.
4546

46-
```python
47-
new_filelink = client.upload(filepath="path/to/file", multipart=False)
48-
```
4947
#### Uploading files using Filestack Intelligent Ingestion
5048
To upload files using Filestack Intelligent Ingestion, simply add `intelligent=True` argument
5149
```python
52-
new_filelink = client.upload(filepath="path/to/file", intelligent=True)
50+
new_filelink = client.upload(filepath='path/to/file', intelligent=True)
5351
```
5452
FII always uses multipart uploads. In case of network issues, it will dynamically split file parts into smaller chunks (sacrificing upload speed in favour of upload reliability).
5553

56-
### Create Filelink using Existing Handle
54+
### Working with Filelinks
55+
Filelink objects can by created by uploading new files, or by initializing `filestack.Filelink` with already existing file handle
5756
```python
58-
from filestack import Filelink
59-
new_filelink = Filelink("<YOUR_HANDLE>")
57+
from filestack import Filelink, Client
58+
59+
client = Client('<APIKEY>')
60+
filelink = client.upload(filepath='path/to/file')
61+
filelink.url # 'https://cdn.filestackcontent.com/FILE_HANDLE
62+
63+
# work with previously uploaded file
64+
filelink = Filelink('FILE_HANDLE')
6065
```
6166

6267
### Basic Filelink Functions
6368

64-
With a Filelink, you can download to a local path or get the content of a file. You can also delete or overwrite files if you have security enabled on your account.
69+
With a Filelink, you can download to a local path or get the content of a file. You can also perform various transformations.
6570

6671
```python
6772
file_content = new_filelink.get_content()
6873

69-
response = new_filelink.download("/path/to/file")
74+
size_in_bytes = new_filelink.download('/path/to/file')
75+
76+
filelink.overwrite(filepath='path/to/new/file')
7077

71-
filelink.overwrite(filepath="path/to/new/file")
78+
filelink.resize(width=400).flip()
7279

73-
response = filelink.delete()
80+
filelink.delete()
7481
```
7582

7683
### Transformations
@@ -81,7 +88,7 @@ You can chain transformations on both Filelinks and external URLs. Storing trans
8188
transform = client.transform_external('http://<SOME_URL>')
8289
new_filelink = transform.resize(width=500, height=500).flip().enhance().store()
8390

84-
filelink = Filelink("<YOUR_HANDLE">)
91+
filelink = Filelink('<YOUR_HANDLE'>)
8592
new_filelink = filelink.resize(width=500, height=500).flip().enhance().store()
8693
```
8794

@@ -113,40 +120,55 @@ filelink = av_object.to_filelink()
113120

114121
### Security Objects
115122

116-
Security is set on Client or Filelink classes upon instantiation.
123+
Security is set on Client or Filelink classes upon instantiation and is used to sign all API calls.
117124

118125
```python
119-
from filestack import security
126+
from filestack import Security
120127

121-
json_policy = {"expiry": 253381964415}
122-
security = security(json_policy, '<YOUR_APP_SECRET>')
123-
client = Client("<YOUR_API_KEY", security=security)
128+
policy = {'expiry': 253381964415} # 'expiry' is the only required key
129+
security = Security(policy, '<YOUR_APP_SECRET>')
130+
client = Client('<YOUR_API_KEY', security=security)
124131

125132
# new Filelink object inherits security and will use for all calls
126-
new_filelink = client.upload(filepath="path/to/file")
133+
new_filelink = client.upload(filepath='path/to/file')
134+
135+
# you can also provide Security objects explicitly for some methods
136+
size_in_bytes = filelink.download(security=security)
137+
```
138+
139+
You can also retrieve security details straight from the object:
140+
```python
141+
>>> policy = {'expiry': 253381964415, 'call': ['read']}
142+
>>> security = Security(policy, 'SECURITY-SECRET')
143+
>>> security.policy_b64
144+
'eyJjYWxsIjogWyJyZWFkIl0sICJleHBpcnkiOiAyNTMzODE5NjQ0MTV9'
145+
>>> security.signature
146+
'f61fa1effb0638ab5b6e208d5d2fd9343f8557d8a0bf529c6d8542935f77bb3c'
127147
```
128148

129149
### Webhook verification
130150

131-
You can use `Client.verify_webhook_signature` method to make sure that the webhooks you receive are sent by Filestack.
151+
You can use `filestack.helpers.verify_webhook_signature` method to make sure that the webhooks you receive are sent by Filestack.
132152

133153
```python
134-
from filestack import Client
154+
from filestack.helpers import verify_webhook_signature
135155

136156
# webhook_data is raw content you receive
137157
webhook_data = b'{"action": "fp.upload", "text": {"container": "some-bucket", "url": "https://cdn.filestackcontent.com/Handle", "filename": "filename.png", "client": "Computer", "key": "key_filename.png", "type": "image/png", "size": 1000000}, "id": 50006}'
138158

139-
resp = Client.verify_webhook_signature(
140-
'<YOUR_WEBHOOK_SECRET>', webhook_data,
141-
{'FS-Signature': '<SIGNATURE-FROM-REQUEST-HEADERS>', 'FS-Timestamp': '<TIMESTAMP-FROM-REQUEST-HEADERS>'}
159+
result, details = verify_webhook_signature(
160+
'<YOUR_WEBHOOK_SECRET>',
161+
webhook_data,
162+
{
163+
'FS-Signature': '<SIGNATURE-FROM-REQUEST-HEADERS>',
164+
'FS-Timestamp': '<TIMESTAMP-FROM-REQUEST-HEADERS>'
165+
}
142166
)
143167

144-
if not resp['valid'] and resp['error'] is None:
145-
raise Exception('Webhook signature is invalid')
146-
elif resp['error']:
147-
print('Please check input params: {}'.format(resp['error']))
148-
else:
168+
if result is True:
149169
print('Webhook is valid and was generated by Filestack')
170+
else:
171+
raise Exception(details['error'])
150172
```
151173

152174
## Versioning

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8.1
1+
3.0.0

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/asset-manifest.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/data.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/favicon.ico

-24.3 KB
Binary file not shown.

docs/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)