Filelib Client¶
After the going through the installation process, you can start using the components within the library.
Please ensure you acquired your API Credentials for Authentication
Client¶
Importing Client into scope:¶
Client object will automatically try to authenticate for you.
There are 3 ways you can authenticate
Supported ways to provide Authentication Credentials
Reading from a configuration file is the default when initializing Client
The following credentials_source, and credentials_path are the default values.
If you have your file at a different path, just update the credentials_path value to your path.
A sample ~/.filelib/credentials file looks like this:
Now you can initialize your Client as such:
from filelib import Client
client = Client(
source="storage_ref", # storage configuration reference name.
prefix="my_dir/" # This will be added to the beginning of your file name during storage
access="private" # Depending what service you are using to store your files, you can set the visibility.
credentials_source="file",
credentials_path="~/.filelib/credentials" # path the your configuration file
)
If you prefer utilizing environment variables, you can set your values in your env with the following keys:
Now you can initate your Client as follows:
from filelib import Client
client = Client(
source="storage_ref", # storage configuration reference name.
prefix="my_dir/" # This will be added to the beginning of your file name during storage
access="private" # Depending what service you are using to store your files, you can set the visibility.
credentials_source="env"
)
Adding files for upload¶
After you initialize Client, now you can add files to be uploaded by chunks.
You can provide additional customizations for each file on how you want to handle it.
from filelib import Client, FilelibConfig
client = Client(storage="storage_ref")
# Open file
file = open("~/Downloads/birthday.mp4", "rb")
config = FilelibConfig(storage="storage_ref", prefix="file_prefix", access="file_access")
client.add_file(
file=file,
config=config # You can pass indivual config object per each file customizing it.
workers = 4 # This will enable threading while chunks are being uploaded incresing speed.
ignore_cache=False # This will turn off caching of file upload progress. Defaults to False.
)
Warning
Please note that if you decide to set ignore_cache to True,
the upload will not be able to resume from where it left off if it does not complete successfully.