Skip to content

Commit b347936

Browse files
v1.0.0
v1.0.0
1 parent f7181d7 commit b347936

18 files changed

+1420
-2
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
# Python-Client-API
2-
SendSafely API for Python
1+
# SendSafely Python API
2+
The SendSafely Python API lets you integrate SendSafely secure data transfer capabilities directly into your Python application.
3+
4+
## Quickstart
5+
The example below shows you how to install the SendSafely-Python-API package, import it as a module, and use it to create a package. Make sure that you have [Python 3 or higher installed, as well as pip and Setuptools](https://packaging.python.org/tutorials/installing-packages/).
6+
7+
Install the SendSafely-Python-API package with pip
8+
```console
9+
python3 -m pip install /dist/SendSafely-Python-API-1.0.0.tar.gz
10+
```
11+
12+
Import the SendSafely module to start making your API calls
13+
14+
```python
15+
from sendsafely import SendSafely, Package
16+
```
17+
Create a Sendsafely instance object
18+
```python
19+
sendsafely = SendSafely("https://your-company.sendsafely.com", "API_KEY", "API_SECRET")
20+
```
21+
Create a new package
22+
```python
23+
package = Package(sendsafely)
24+
```
25+
Add a secure message to the package
26+
```python
27+
package.encrypt_and_upload_message("hello this is a message")
28+
```
29+
Add a recipient to the package
30+
```python
31+
package.add_recipient("user@foobar.com")
32+
```
33+
Finalize the package so it can be delivered to the recipients. The returned response contains the Secure Link needed for recipients to access the package.
34+
```python
35+
response = package.finalize()
36+
```
37+
*You will need to generate your own API_KEY and API_SECRET from the API Keys section of your Profile page when logged into your SendSafely portal.*
38+
39+
## Examples
40+
**sendsafely_python_example.py** - demonstrates how the SendSafely Python API can be used to create packages and handle encrypt/upload and download/decrypt operations without the API developer having to implement these complex operations.
41+
```
42+
python3 sendsafely_python_example.py
43+
```
44+
45+
**sendsafely_rest_example.py** - demonstrates how the SendSafely Python API can be used to call SendSafely REST API endpoints directly. This is useful for cases where the SendSafely Python API does not currently implement a function for calling the endpoint.
46+
```
47+
python3 sendsafely_rest_example.py
48+
```
49+
50+
*Before running the example scripts, you will need to update the `api_key`, `api_secret`, and `base_url` variables in the script before running it.*
51+
52+
For more information, please refer to our [Developer Website](https://sendsafely.github.io) to familiarize yourself with the core SendSafely API and common operations. You can find our documented REST API endpoints [here](https://bump.sh/doc/sendsafely-rest-api).
53+
54+
## Support
55+
For support, please contact support@sendsafely.com.

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cp README.md src/README
2+
cd src
3+
python3 setup.py sdist --dist-dir=../dist
4+
cd ..
11 KB
Binary file not shown.

scripts/fileToUpload.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Thank you for using SendSafely! :)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
3+
from sendsafely import SendSafely, Package, Progress
4+
5+
6+
class CustomProgress(Progress):
7+
8+
def update_progress(self, file_id, progress):
9+
self.progress = progress
10+
11+
if progress == '100.0':
12+
last = '\n'
13+
else:
14+
last = ''
15+
16+
sys.stdout.write('\rCustom Progress for fileId {0}: {1}{2} complete{3}'.format(file_id, progress, '%', last))
17+
sys.stdout.flush()
18+
19+
20+
sendsafely = SendSafely("https://companyabc.sendsafely.com", "", "")
21+
package = Package(sendsafely)
22+
recipient = "me@sendsafely.net"
23+
recipient = package.add_recipient(recipient)
24+
test_file_path = "fileToUpload.txt"
25+
# custom case
26+
custom = package.encrypt_and_upload_file(test_file_path, progress_instance=CustomProgress())
27+
# default case
28+
default = package.encrypt_and_upload_file(test_file_path)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import json
2+
3+
from sendsafely import SendSafely, Package
4+
5+
# Edit these variables
6+
api_key = ""
7+
api_secret = ""
8+
base_url = "https://companyabc.sendsafely.com"
9+
# Make sure all directories exist on your file system
10+
upload_file = "fileToUpload.txt"
11+
download_filename = "fileDownloaded.txt"
12+
download_dir = "."
13+
recipient = "user@foobar.com"
14+
15+
def main():
16+
sendsafely = SendSafely(base_url, api_key, api_secret)
17+
package = Package(sendsafely)
18+
19+
with open(upload_file, 'wb') as file:
20+
content = bytes("SendSafely lets you easily exchange encrypted files and information with anyone on any device.", "utf-8")
21+
file.write(content)
22+
23+
f = package.encrypt_and_upload_file(upload_file)
24+
file_id = f["fileId"]
25+
print("Successfully encrypted and uploaded file id " + str(file_id))
26+
27+
package.encrypt_and_upload_message("hello this is a message")
28+
print("Successfully encrypted and uploaded secure message")
29+
30+
package.add_recipient(recipient)
31+
print("Successfully added recipient " + recipient)
32+
33+
response = package.finalize()
34+
print("Successfully submitted package - link for sending: " + response["message"])
35+
36+
package.download_and_decrypt_file(file_id, download_directory=download_dir, file_name=download_filename)
37+
print("Successfully downloaded and decrypted file " + download_filename)
38+
39+
print("Package Info: ")
40+
print(json.dumps(package.get_info(), indent=4, sort_keys=True))
41+
42+
if __name__ == '__main__':
43+
main()

scripts/sendsafely_rest_example.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from sendsafely import SendSafely, Package, utilities
2+
3+
# Edit these variables
4+
api_key = ""
5+
api_secret = ""
6+
base_url = "https://companyabc.sendsafely.com"
7+
8+
9+
def rest_get_example_user_information(sendsafely):
10+
get_endpoint = "/user/"
11+
response = utilities.get_request(sendsafely, get_endpoint)
12+
print(response)
13+
14+
15+
def rest_post_example_update_package_life(sendsafely):
16+
package = Package(sendsafely)
17+
post_endpoint = "/package/" + package.package_id
18+
body = {"life": 10}
19+
response = utilities.post_request(sendsafely, post_endpoint, body)
20+
print(response)
21+
22+
23+
def rest_delete_example_delete_package(sendsafely):
24+
package = Package(sendsafely)
25+
delete_endpoint = "/package/" + package.package_id
26+
response = utilities.delete_request(sendsafely, delete_endpoint)
27+
print(response)
28+
29+
30+
def rest_put_example_add_recipients(sendsafely):
31+
package = Package(sendsafely)
32+
put_endpoint = "/package/" + package.package_id + "/recipients/"
33+
response = utilities.put_request(sendsafely, put_endpoint,
34+
{'emails': ['user@foobar.com', 'user2@foobar.com']})
35+
print(response)
36+
37+
38+
def rest_patch_example_update_file(sendsafely):
39+
# Edit
40+
package_id = 'packageId of Dropzone package'
41+
file_id = 'fileId of Dropzone package'
42+
body = {'fileName': 'new file name'}
43+
44+
patch_endpoint = "/package/" + package_id + "/file/" + file_id
45+
response = utilities.patch_request(sendsafely, patch_endpoint, body)
46+
print(response)
47+
48+
49+
def main():
50+
sendsafely = SendSafely(base_url, api_key, api_secret)
51+
print("GET: User Information")
52+
rest_get_example_user_information(sendsafely)
53+
print("POST: Update Package Life")
54+
rest_post_example_update_package_life(sendsafely)
55+
print("PUT: Add Recipients")
56+
rest_put_example_add_recipients(sendsafely)
57+
print("DELETE: Delete Package")
58+
rest_delete_example_delete_package(sendsafely)
59+
# print("PATCH: Update Dropzone File")
60+
# rest_patch_example_update_file(sendsafely)
61+
62+
63+
if __name__ == '__main__':
64+
main()

src/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
README
2+
MANIFEST

src/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README

src/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests~=2.24.0
2+
PGPy~=0.5.3

0 commit comments

Comments
 (0)