def __init__(self, endpoint: str, access_id: str | None = None, secret_key: str | None = None, region: str | None = None, http_client: urllib3.PoolManager | None = None, cert_check: bool = True):
endpoint
(str): The API endpoint.access_id
(str, optional): Access ID for authentication.secret_key
(str, optional): Secret key for authentication.region
(str, optional): Region specification.http_client
(urllib3.PoolManager, optional): Custom HTTP client.cert_check
(bool, optional): Enable/disable certificate checks. Default isTrue
.
tonic = Tonic(endpoint="https://api.example.com", access_id="my_access_id", secret_key="my_secret_key")
The returning structure from each method in the API
status
The status of the call, eithersuccess
,error
orwarning
status_code
The HTML status code for the callresult
The resulting data set for the callresult2
For certain calls, a second set of result data set can be returnedmessage
Any additional message from the call (generally used for errors and warnings)
def client_response(self, method: str, url: str, body: bytes | None = None, json: dict | None = None)
Get a response from the server. This can be used to define your own methods.
method
(str): GET, POST, PUT or DELETEurl
(str): The url to call, this excludes the endpoint.body
(bytes, optional): The bytes to be passed.json
(bool, optional): The json to be passed.
json
: Response from the server.
response = tonic.client_response("GET", "/status?node_only=true")
def create_bucket(self, bucket: str, acl: BUCKET_ACL = BUCKET_ACL.PRIVATE, bucket_locked: bool = False) -> json:
Creates a new bucket.
bucket
(str): Name of the bucket.acl
(BUCKET_ACL, optional): Access control level. Default isBUCKET_ACL.PRIVATE
.bucket_locked
(bool, optional): Indicates if the bucket should be locked. Default isFalse
.
json
: Response from the server.
response = tonic.create_bucket(bucket="my_bucket")
def list_buckets(self) -> list[Bucket]:
Lists all buckets.
list[Bucket]
: List of buckets.
buckets = tonic.list_buckets()
def delete_bucket(self, bucket: str) -> json:
Deletes a bucket.
bucket
(str): Name of the bucket to delete.
json
: Response from the server.
response = tonic.delete_bucket(bucket="my_bucket")
def put_object(self, bucket: str, key: str, file: str | BinaryIO, content_type: str = "application/octet-stream", verify_sha256: bool = False) -> json:
Uploads an object to a bucket.
bucket
(str): Name of the bucket.key
(str): Key of the object.file
(str | BinaryIO): File path or file data.content_type
(str, optional): Content type of the object. Default is"application/octet-stream"
.verify_sha256
(bool, optional): Verify object checksum. Default isFalse
.
json
: Response from the server.
response = tonic.put_object(bucket="my_bucket", key="my_object", file="path/to/file")
def list_objects(self, bucket: str) -> list[Object]:
Lists all objects in a bucket.
bucket
(str): Name of the bucket.
list[Object]
: List of objects.
objects = tonic.list_objects(bucket="my_bucket")
def get_object_checksum(self, bucket: str, key: str, algorithm: OBJECT_CHECKSUM_ALGORITHMS) -> str:
Gets the checksum of an object.
bucket
(str): Name of the bucket.key
(str): Key of the object.algorithm
(OBJECT_CHECKSUM_ALGORITHMS): Checksum algorithm.
str
: Object checksum.
checksum = tonic.get_object_checksum(bucket="my_bucket", key="my_object", algorithm=OBJECT_CHECKSUM_ALGORITHMS.SHA256)
def get_object(self, bucket: str, key: str, file_path: str) -> json:
Downloads an object to a specified file path.
bucket
(str): Name of the bucket.key
(str): Key of the object.file_path
(str): Path to save the downloaded object.
json
: Response from the server.
response = tonic.get_object(bucket="my_bucket", key="my_object", file_path="path/to/save")