Craedl Python SDK documentation¶
Core¶
Auth¶
-
class
craedl.core.
Auth
(host=None)[source]¶ This base class handles low-level RESTful API communications. Any class that needs to perform RESTful API communications should extend this class.
-
DELETE
(path)[source]¶ Handle a DELETE request.
Parameters: path (string) – the RESTful API method path Returns: a dict containing the contents of the parsed JSON response or an HTML error string if the response does not have status 200
-
GET
(path, data=False)[source]¶ Handle a GET request.
Parameters: - path (string) – the RESTful API method path
- data (boolean) – whether the response is a data stream (default False)
Returns: a dict containing the contents of the parsed JSON response, data stream, or an HTML error string if the response does not have status 200
-
POST
(path, data, filepath=None)[source]¶ Handle a POST request.
Parameters: - path (string) – the RESTful API method path
- data (dict) – the data to POST to the RESTful API method as described at https://api.craedl.org
- filepath (string) – the path to the file to be passed
Returns: a dict containing the contents of the parsed JSON response or an HTML error string if the response does not have status 200
-
Craedl¶
-
class
craedl.core.
Craedl
(host, slug, id=None, data={})[source]¶ A Craedl. Get a Craedl from the API by passing id. Get a Craedl from an existing dictionary (for example, a child carried by a parent)without any network traffic by passing data.
Inode¶
-
class
craedl.core.
Inode
(craedl, id=None, data={})[source]¶ A Craedl inode (directory or file) object. Get an Inode from the API by passing id. Get an Inode from an eisting dictionary (for example, a child carried by a parent) without any network traffic by passing data.
-
abspath
()[source]¶ Get a string representation of the absolute path for an inode.
Returns: a string containing the absolute path for an inode
-
create_directory
(name)[source]¶ Create a new directory within the current directory.
Parameters: name (string) – the name of the new directory Returns: the new Inode
-
download
(save_path, rescan=True, output=False, accumulated_size=0)[source]¶ Download the contents of the current Inode into save_path. If the current Inode is a directory, download recursively; this generates a cache database file in the save_path that is used to enhance performance of retries and synchronizations.
Parameters: - save_path (string) – the path to the directory on your computer that will contain this file’s data
- rescan (boolean) – whether to rescan the directories (defaults to True); ignores new children in already transferred directories if False
- output (boolean) – whether to print to STDOUT (defaults to False)
- accumulated_size – the total size of the download so far; primarily supports recursive download output messages
Returns: a tuple containing the updated instance of this directory and the size of the download
-
download_recurse
(cache, save_path, rescan, output, accumulated_size)[source]¶ The recursive function that does the downloading. There is little reason to call this directly; use
Inode.download()
to start a recursive directory download.Parameters: - cache (
Cache
) – the cache database - save_path (string) – the path to the directory on your computer that will contain this file’s data
- rescan (boolean) – whether to rescan the directories (defaults to True); ignores new children in already transferred directories if False
- output (boolean) – whether to print to STDOUT (defaults to False)
- accumulated_size – the amount of data that has been downloaded so far
Type: integer
Returns: a tuple containing the updated instance of this directory and the amount of data that has been downloaded by this recursion level and its children
- cache (
-
get
(path)[source]¶ Get a particular directory or file. This may be an absolute or relative path.
Parameters: path (string) – the directory or file path Returns: the requested directory or file
-
list
()[source]¶ List the contents of this directory.
Returns: a dictionary containing a list of directories (‘dirs’) and a list of files (‘files’)
-
upload
(path, rescan=True, output=False, follow_symlinks=False)[source]¶ Upload to the current directory. If uploading a directory, this generates a cache database in the path that is used to enhanceperformance of retries and synchronizations.
Parameters: - path (string) – the local path to the file/directory to be uploaded
- rescan (boolean) – whether to rescan the directories (defaults to True); ignores new children in already transferred directories if False
- output (boolean) – whether to print to STDOUT (defaults to False)
- follow_symlinks (boolean) – whether to follow symlinks (default False)
Returns: the uploaded Inode
-
upload_directory
(directory_path, rescan=True, follow_symlinks=False, output=False)[source]¶ Upload a new directory contained within this directory. It generates a cache database in the directory_path that is used to enhance performance of retries and synchronizations.
Parameters: - directory_path (string) – the path to the directory to be uploaded on your computer
- follow_symlinks (boolean) – whether to follow symlinks (default False)
- rescan (boolean) – whether to rescan the directories (defaults to True); ignores new children in already transferred directories if False
- output (boolean) – whether to print to STDOUT (defaults to False)
Returns: the updated instance of the current directory
-
upload_directory_recurse
(cache, directory_path, rescan, follow_symlinks, output, accumulated_size)[source]¶ The recursive function that does the uploading. There is little reason to call this directly; use
Directory.upload_directory()
to start a directory upload.Parameters: - cache (
Cache
) – the cache database - directory_path (string) – the path to the directory on your computer that will contain this file’s data
- rescan (boolean) – whether to rescan the directories (defaults to True); ignores new children in already transferred directories if False
- follow_symlinks (boolean) – whether to follow symlinks
- output (boolean) – whether to print to STDOUT
- accumulated_size – the amount of data that has been uploaded so far
Type: int
Returns: a tuple containing the updated instance of this directory and the amount of data that has been downloaded by this recursion level and its children
- cache (
-
upload_file
(file_path, output=False, accumulated_size=0)[source]¶ Upload a new file contained within this directory.
Parameters: - file_path (string) – the path to the file to be uploaded on your computer
- output (boolean) – whether to print to STDOUT (defaults to False)
- accumulated_size (int) – the size that has accumulated prior to this upload (defaults to 0); this is entirely for output purposes
Returns: a tuple with the updated instance of the current directory and the uploaded size
-
Profile¶
-
class
craedl.core.
Profile
(id=None, data=None)[source]¶ A Craedl profile object. Get a Profile from the API by passing id. Get a Profile from an existing dictionary without network traffic by passing data. Get your profile by passing no arguments.
Cache¶
Cache¶
-
class
craedl.cache.
Cache
[source]¶ This class handles all cache database operations. It is used largely in support of recursive file uploads and downloads.
It operates by storing a SHA1 hash representing the time stamps for children within a given directory and a status bit that indicates whether the contents were successfully transferred at the time the hash was created.