Skip to main content

File repository API Client

Project description

file-repository-api-client

A small api client library used with a file repository Api.

Installation

pip install file-repository-api-client

Save file to File Repository API

from file_repository_api_client import FileApi

url: str = "https://file.example.api.com/files"
file: str = "~/my_file.txt"

api = FileApi(url)

resp: dict = api.store_file(file)

#get file guid
print(resp["results"]["guid"])

Retrieve file from File Repository API

Send file to repository API for storage:

import requests
from file_repository_api_client import FileApi


url: str = "https://file.example.api.com/files"
guid: str = "bd353120-e0ed-4400-83f1-9eba80db2809"

api = FileApi(url)

resp: dict = api.retrieve_file(guid)

#specify local file name
file_name: str = f"{resp['results']['name']}"

try:
    response = requests.get(resp["results"]["presigned_url"], allow_redirects=True)
    response.raise_for_status()
    with open(file_name, mode="w", encoding="utf-8") as f:
        f.write(response.content.decode("utf-8"))
except requests.exceptions.HTTPError as err:
    print(f"Exception occurred whilst attempting download file from api, error: {err}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

file-repository-api-client-0.1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file file-repository-api-client-0.1.0.tar.gz.

File metadata

File hashes

Hashes for file-repository-api-client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa30f09fb4353cca95b9842099238f9f6f2bdbba601c297f8a58235c9541652e
MD5 a0a32808d54731cf203825225385ed98
BLAKE2b-256 9621688a1de6e0130844ef2d95a309d00a039b05aaeb369f4875e497641d51ee

See more details on using hashes here.

File details

Details for the file file_repository_api_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for file_repository_api_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0eb39e223b60bc2d39f493f31813bbce5ef0c736e38f7b112760fda0cab20944
MD5 ef5cd98cffc900054b8e340892c1e9e9
BLAKE2b-256 c7cb6b49e4c3b92d472350741afb61e74115b4f249cf72dce1c12bd7e0ec1047

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page