Skip to content

Commit 1335b5e

Browse files
author
Bartek Kwiecien
committed
Updated readme [skip ci]
1 parent 9e3b170 commit 1335b5e

File tree

2 files changed

+60
-39
lines changed

2 files changed

+60
-39
lines changed

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

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ def read_version():
2222
author='filestack.com',
2323
author_email='support@filestack.com',
2424
packages=find_packages(),
25-
install_requires=['requests', 'trafaret', 'future'],
25+
install_requires=['requests', 'trafaret'],
2626
classifiers=[
2727
'Development Status :: 4 - Beta',
2828
'Intended Audience :: Developers',
2929
'License :: OSI Approved :: Apache Software License',
3030
'Programming Language :: Python',
31-
'Programming Language :: Python :: 2.7',
32-
'Programming Language :: Python :: 3.4',
3331
'Programming Language :: Python :: 3.5',
3432
'Programming Language :: Python :: 3.6',
33+
'Programming Language :: Python :: 3.7',
3534
'Topic :: Internet :: WWW/HTTP',
3635
],
3736
)

0 commit comments

Comments
 (0)