Newtera Python SDK for Newtera TDM
Project description
Newtera Python Client SDK for Newtera TDM service
The Newtera Python Client SDK provides high level APIs to access any Newtera TDM service.
This Quickstart Guide covers how to install the Newtera client SDK, connect to the Newtera TDM, and access the test data files.
The example below uses:
-
The Newtera TDM local server
For a complete list of APIs and examples, see the Python Client API Reference
Install the Newtera Python SDK
The Python SDK requires Python version 3.7+.
You can install the SDK with pip or from the Newtera/Newtera-py GitHub repository:
Using pip
pip3 install Newtera
Using Source From GitHub
git clone https://github.com/yong-zhang-newtera/Newtera-py
cd Newtera-py
python setup.py install
Create a Newtera Client
To connect to the target service, create a Newtera client using the Newtera() method with the following required parameters:
| Parameter | Description |
|--------------|--------------------------------------------------------|
| endpoint | URL of the target service. |
| access_key | Access key (user ID) of a user account in the service. |
| secret_key | Secret key (password) for the user account. |
For example:
from Newtera import Newtera
client = Newtera("localhost:8080",
access_key="demo1",
secret_key="888",
)
Example - Upload a file
This example does the following:
-
Connects to the Newtera TDM localhost server using the provided credentials.
-
Uploads a file named
test-file.txtfrom/tmp, renaming itmy-test-file.txt.
upload_file.py
from Newtera import Newtera
from Newtera.error import NewteraError
def main():
# Create a client with the Newtera server playground, its access key
# and secret key.
client = Newtera("localhost:8080",
access_key="demo1",
secret_key="888",
)
# The file to upload, change this path if needed
source_file = "/tmp/test-file.txt"
# The destination bucket and filename on the Newtera server
bucket_name = "tdm"
prefix = "task001/test-item001/data-packet001"
destination_file = "my-test-file.txt"
# Make the bucket if it doesn't exist.
found = client.bucket_exists(bucket_name)
if found:
print("Bucket", bucket_name, "already exists")
# Upload the file, renaming it in the process
client.fput_object(
bucket_name, prefix, destination_file, source_file,
)
print(
source_file, "successfully uploaded as object",
destination_file, "to bucket", bucket_name,
)
if __name__ == "__main__":
try:
main()
except NewteraError as exc:
print("error occurred.", exc)
To run this example:
-
Create a file in
/tmpnamedtest-file.txt.To use a different path or filename, modify the value of
source_file. -
Run
upload_file.pywith the following command:
python upload_file.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file newtera-1.0.0.tar.gz.
File metadata
- Download URL: newtera-1.0.0.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2242516416b54e7a8cc305dbefcbc47f5ccf7f55fe2c9b4cb7cdbbb33cea81ef
|
|
| MD5 |
dd0cd5d2bc0e52ac214249ebc03e50d6
|
|
| BLAKE2b-256 |
2326b9b60b780302b3a270c2def75d6a10b6fbd00c30992bdcd4111f0a8e96ab
|