UploadFly Python SDK
The Python SDK provides a convenient interface for interacting with the UploadFly API to upload and delete files.
from github
pip install -e git+https://github.com/uploadfly/pythonfrom PyPi repository(coming soon)
pip install uploadfly- Creates new instance of the
UploadflyClientclass - Parameters:
api_key(string): The API key required for authentication with the UploadFly service.
- Throws:
Exception: If theapi_keyparameter is not provided.
- Uploads a file to the Uploadfly cloud.
- Parameters:
file(BufferedReader or string): The file to be uploaded. BufferedReader can be created by using theopen('filename', 'rb')function.filename(string): The desired filename for the uploaded file. If not provided, the original filename will be used.
- Returns:
- response from the Uploadfly API.
- Throws:
Exception: If thefileparameter is not provided or if the file upload fails.Exception: If an error occurs during the file upload process.
- Deletes a file from the Uploadfly cloud.
- Parameters:
file_url(string): The URL of the file to be deleted.
- Returns:
- response from the Uploadfly API.
- Throws:
Exception: If thefile_urlparameter is not provided or if the file deletion fails.Exception: If an error occurs during the file deletion process.
from uploadfly import UploadflyClient
uploadfly = UploadflyClient('your-api-key')
# upload with BufferedReader
file = open('file.txt', 'rb')
try:
response = uploadfly.upload(file, filename='custom-filename')
print('file uploaded', response)
except Exception as e:
print('error uploading file', str(e))
# upload with file path
file = 'path/to/file'
try:
response = uploadfly.upload(file, filename='custom-filename')
print('file uploaded', response)
except Exception as e:
print('error uploading file', str(e))file_url = # file url
try:
response = uploadfly.delete(file_url)
print('file deleted', response)
except Exception as e:
print('error deleting file', str(e))