FileApi¶
- class FileApi(api)[source]¶
Bases:
ModuleApiBaseAPI for working with files in Team Files.
- Parameters:
- Usage Example:
import supervisely as sly api = sly.Api.from_env() files = api.file.list(team_id, file_path)
Methods
Convert information about an entity to a dictionary.
Checks if directory exists in Team Files.
Download File from Team Files.
Download File from Team Files.
Download multiple Files from Team Files.
Download Directory from Team Files.
Download Directory from Team Files to local path asynchronously.
download_from_agentDownloads data for application from input using environment variables.
Asynchronously downloads data for the application, using a path from file/folder selector.
Checks if file exists in Team Files.
Get directory size in the Team Files.
Adds suffix to the end of the Directory name.
Adds suffix to the end of the file name.
Gets information about File by ID.
Gets File information by path in Team Files.
Get JSON file content.
Get list of all or limited quantity entities from the Supervisely server.
This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved
Get the list of items for a given page number.
Yields list of images in dataset asynchronously page by page.
Gets URL for the File by ID.
Sequence of fields that are returned by the API to represent FileInfo.
Name of the tuple that represents FileInfo.
is_on_agentList of files in the Team Files.
Disclaimer: Method is not recommended.
List of files in the Team Files.
List dirs and files in the directiry with given path.
Loads .env file from Team Files into environment variables.
parse_agent_id_and_pathRemoves a file from the Team Files.
Removes list of files from Team Files.
Removes folder from Team Files.
Removes file from Team Files.
remove_from_agentRenames file in Team Files
Upload File to Team Files.
Upload file from local path to Team Files asynchronously.
Upload Files to Team Files.
Upload multiple files from local paths to Team Files asynchronously.
Upload multiple files from local paths to Team Files in fast mode.
Upload Directory to Team Files from local path.
Upload Directory to Team Files from local path.
Upload Directory to Team Files from local path in fast mode.
Attributes
MAX_WAIT_ATTEMPTSMaximum number of attempts that will be made to wait for a certain condition to be met.
WAIT_ATTEMPT_TIMEOUT_SECNumber of seconds for intervals between attempts.
- InfoType¶
alias of
FileInfo
- static info_sequence()[source]¶
Sequence of fields that are returned by the API to represent FileInfo.
- Usage Example:
FileInfo( team_id=8, id=7660, user_id=7, name='00135.json', hash='z7Hv9a7WIC5HIJrfX/69KVrvtDaLqucSprWHoCxyq0M=', path='/999_App_Test/ds1/00135.json', storage_path='/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json', mime='application/json', ext='json', sizeb=261, created_at='2021-01-11T09:04:17.959Z', updated_at='2021-01-11T09:04:17.959Z', full_storage_url='http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json' )
-
dir_exists(team_id, remote_directory, recursive=
True)[source]¶ Checks if directory exists in Team Files.
- Parameters:
- Returns:
True if directory exists, otherwise False
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file = api.file.dir_exists(8, "/999_App_Test/") # True file = api.file.dir_exists(8, "/10000_App_Test/") # False
-
download(team_id, remote_path, local_save_path, cache=
None, progress_cb=None)[source]¶ Download File from Team Files.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_file = "/999_App_Test/ds1/01587.json" local_save_path = "/home/admin/Downloads/01587.json" api.file.download(8, path_to_file, local_save_path)
-
async download_async(team_id, remote_path, local_save_path, semaphore=
None, cache=None, progress_cb=None, progress_cb_type='size')[source]¶ Download File from Team Files.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- remote_path : str¶
Path to File in Team Files.
- local_save_path : str¶
Local save path.
- semaphore : asyncio.Semaphore¶
Semaphore for limiting the number of simultaneous downloads.
- cache=
None¶ Cache object for storing files.
- progress_cb : tqdm or callable, optional¶
Function for tracking download progress.
- progress_cb_type : Literal["number", "size"], optional¶
Type of progress callback. Can be “number” or “size”. Default is “size”.
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_file = "/999_App_Test/ds1/01587.json" local_save_path = "/path/to/save/999_App_Test/ds1/01587.json" loop = sly.utils.get_or_create_event_loop() loop.run_until_complete(api.file.download_async(8, path_to_file, local_save_path))
-
async download_bulk_async(team_id, remote_paths, local_save_paths, semaphore=
None, caches=None, progress_cb=None, progress_cb_type='size')[source]¶ Download multiple Files from Team Files.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- remote_paths : List[str]¶
List of paths to Files in Team Files.
- local_save_paths : List[str]¶
List of local save paths.
- semaphore : asyncio.Semaphore¶
Semaphore for limiting the number of simultaneous downloads.
- caches=
None¶ List of cache objects for storing files.
- progress_cb : tqdm or callable, optional¶
Function for tracking download progress.
- progress_cb_type : Literal["number", "size"], optional¶
Type of progress callback. Can be “number” or “size”. Default is “size”.
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() paths_to_files = [ "/999_App_Test/ds1/01587.json", "/999_App_Test/ds1/01588.json", "/999_App_Test/ds1/01587.json" ] local_paths = [ "/path/to/save/999_App_Test/ds1/01587.json", "/path/to/save/999_App_Test/ds1/01588.json", "/path/to/save/999_App_Test/ds1/01587.json" ] loop = sly.utils.get_or_create_event_loop() loop.run_until_complete( api.file.download_bulk_async(8, paths_to_files, local_paths) )
-
download_directory(team_id, remote_path, local_save_path, progress_cb=
None)[source]¶ Download Directory from Team Files.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_dir = "/My_App_Test/ds1" local_save_path = "/home/admin/Downloads/My_local_test" api.file.download_directory(9, path_to_dir, local_save_path)
-
async download_directory_async(team_id, remote_path, local_save_path, semaphore=
None, show_progress=True)[source]¶ Download Directory from Team Files to local path asynchronously.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_dir = "/files/folder" local_path = "path/to/local/folder" loop = sly.utils.get_or_create_event_loop() loop.run_until_complete( api.file.download_directory_async(9, path_to_dir, local_path) )
-
download_input(save_path, unpack_if_archive=
True, remove_archive=True, force=False, log_progress=False)[source]¶ Downloads data for application from input using environment variables. Automatically detects if data is a file or a directory and saves it to the specified directory. If data is an archive, it will be unpacked to the specified directory if unpack_if_archive is True.
- Parameters:
- save_path : str¶
path to a directory where data will be saved
- unpack_if_archive : Optional[bool]¶
if True, archive will be unpacked to the specified directory
- remove_archive : Optional[bool]¶
if True, archive will be removed after unpacking
- force : Optional[bool]¶
if True, data will be downloaded even if it already exists in the specified directory
- log_progress : bool¶
if True, progress bar will be displayed
- Raises:
if both file and folder paths not found in environment variables
if both file and folder paths found in environment variables (debug)
if team id not found in environment variables
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() # Application is started... save_path = "/my_app_data" api.file.download_input(save_path) # The data is downloaded to the specified directory.
-
async download_input_async(save_path, semaphore=
None, unpack_if_archive=True, remove_archive=True, force=False, show_progress=False)[source]¶ Asynchronously downloads data for the application, using a path from file/folder selector. The application adds this path to environment variables, which the method then reads. Automatically detects if data is a file or a directory and saves it to the specified directory. If data is an archive, it will be unpacked to the specified directory if unpack_if_archive is True.
- Parameters:
- save_path : str¶
path to a directory where data will be saved
- semaphore : asyncio.Semaphore¶
Semaphore for limiting the number of simultaneous downloads
- unpack_if_archive : Optional[bool]¶
if True, archive will be unpacked to the specified directory
- remove_archive : Optional[bool]¶
if True, archive will be removed after unpacking
- force : Optional[bool]¶
if True, data will be downloaded even if it already exists in the specified directory
- show_progress : bool¶
if True, progress bar will be displayed
- Raises:
if both file and folder paths not found in environment variables
if both file and folder paths found in environment variables (debug)
if team id not found in environment variables
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() # Application is started... save_path = "/my_app_data" loop = sly.utils.get_or_create_event_loop() loop.run_until_complete( api.file.download_input_async(save_path) ) # The data is downloaded to the specified directory.
-
exists(team_id, remote_path, recursive=
True)[source]¶ Checks if file exists in Team Files.
- Parameters:
- Returns:
True if file exists, otherwise False
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file = api.file.exists(8, "/999_App_Test/ds1/02163.json") # True file = api.file.exists(8, "/999_App_Test/ds1/01587.json") # False
- get_directory_size(team_id, path)[source]¶
Get directory size in the Team Files. If directory is on local agent, then optimized method will be used (without api requests)
- Parameters:
- Returns:
Directory size in the Team Files
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() team_id = 9 path = "/My_App_Test/" size = api.file.get_directory_size(team_id, path) print(size) # Output: 3478687
- get_free_dir_name(team_id, dir_path)[source]¶
Adds suffix to the end of the Directory name.
- Parameters:
- Returns:
New Directory name with suffix at the end
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() new_dir_name = api.file.get_free_dir_name(9, "/My_App_Test") print(new_dir_name) # Output: /My_App_Test_001
- get_free_name(team_id, path)[source]¶
Adds suffix to the end of the file name.
- Parameters:
- Returns:
New File name with suffix at the end
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file = api.file.get_free_name(8, "/999_App_Test/ds1/02163.json") print(file) # Output: /999_App_Test/ds1/02163_000.json
- get_info_by_id(id)[source]¶
Gets information about File by ID.
- Parameters:
- Returns:
Information about file.
- Return type:
FileInfo- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file_id = 7660 file_info = api.file.get_info_by_id(file_id) print(file_info) # Output: FileInfo(team_id=8, # id=7660, # user_id=7, # name='00135.json', # hash='z7Hv9a7WIC5HIJrfX/69KVrvtDaLqucSprWHoCxyq0M=', # path='/999_App_Test/ds1/00135.json', # storage_path='/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json', # mime='application/json', # ext='json', # sizeb=261, # created_at='2021-01-11T09:04:17.959Z', # updated_at='2021-01-11T09:04:17.959Z', # full_storage_url='http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json')
- get_info_by_path(team_id, remote_path)[source]¶
Gets File information by path in Team Files.
- Parameters:
- Returns:
Information about file.
- Return type:
FileInfo- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file_path = "/999_App_Test/ds1/00135.json" file_info = api.file.get_info_by_id(8, file_path) print(file_info) # Output: FileInfo(team_id=8, # id=7660, # user_id=7, # name='00135.json', # hash='z7Hv9a7WIC5HIJrfX/69KVrvtDaLqucSprWHoCxyq0M=', # path='/999_App_Test/ds1/00135.json', # storage_path='/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json', # mime='application/json', # ext='json', # sizeb=261, # created_at='2021-01-11T09:04:17.959Z', # updated_at='2021-01-11T09:04:17.959Z', # full_storage_url='http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json')
-
get_json_file_content(team_id, remote_path, download=
False)[source]¶ Get JSON file content.
- Parameters:
- Returns:
JSON file content
- Return type:
dict or None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file_content = api.file.get_json_file_content() print(file_content)
-
get_list_all_pages(method, data, progress_cb=
None, convert_json_info_cb=None, limit=None, return_first_response=False)¶ Get list of all or limited quantity entities from the Supervisely server.
- Parameters:
- method : str¶
Request method name
- data : dict¶
Dictionary with request body info
- progress_cb : Progress, optional¶
Function for tracking download progress.
- convert_json_info_cb : Callable, optional¶
Function for convert json info
- limit : int, optional¶
Number of entity to retrieve
- return_first_response : bool, optional¶
Specify if return first response
- Returns:
List of entities.
- Return type:
List[dict]
-
get_list_all_pages_generator(method, data, progress_cb=
None, convert_json_info_cb=None, limit=None, return_first_response=False)¶ This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved
- Parameters:
- method : str¶
Request method name
- data : dict¶
Dictionary with request body info
- progress_cb : Progress, optional¶
Function for tracking download progress.
- convert_json_info_cb : Callable, optional¶
Function for convert json info
- limit : int, optional¶
Number of entity to retrieve
- return_first_response : bool, optional¶
Specify if return first response
- async get_list_idx_page_async(method, data)¶
Get the list of items for a given page number. Page number is specified in the data dictionary.
-
async get_list_page_generator_async(method, data, pages_count=
None, semaphore=None)¶ Yields list of images in dataset asynchronously page by page.
- Parameters:
- method : str¶
Method to call for listing items.
- data : dict¶
Data to pass to the API method.
- pages_count : int, optional¶
Preferred number of pages to retrieve if used with a
per_pagelimit. Will be automatically adjusted if thepagesCountdiffers from the requested number.- semaphore=
None¶ Semaphore for limiting the number of simultaneous requests.
- Returns:
List of images in dataset.
- Return type:
AsyncGenerator[List[
ImageInfo]]- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() method = 'images.list' data = {'datasetId': 123456} loop = sly.utils.get_or_create_event_loop() images = loop.run_until_complete(api.image.get_list_generator_async(method, data))
- get_url(file_id)[source]¶
Gets URL for the File by ID.
- Parameters:
- Returns:
File URL
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() file_id = 7660 file_url = api.file.get_url(file_id) print(file_url) # Output: http://supervisely.com/files/7660
-
list(team_id, path, recursive=
True, return_type='dict')[source]¶ List of files in the Team Files.
- Parameters:
- Returns:
List of all Files with information.
- Return type:
List[Union[Dict,
FileInfo]]- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() team_id = 8 file_path = "/999_App_Test/" # Get information about file in dict way.. files = api.file.list(team_id, file_path) file = files[0] print(file['id']) # Output: 7660 print(files) # Output: [ # { # "id":7660, # "userId":7, # "path":"/999_App_Test/ds1/00135.json", # "storagePath":"/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json", # "meta":{ # "ext":"json", # "mime":"application/json", # "size":261 # }, # "createdAt":"2021-01-11T09:04:17.959Z", # "updatedAt":"2021-01-11T09:04:17.959Z", # "hash":"z7Wv1a7WIC5HIJrfX/69XXrqtDaLxucSprWHoCxyq0M=", # "fullStorageUrl":"http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/y/P/rn/...json", # "teamId":8, # "name":"00135.json" # }, # { # "id":7661, # "userId":7, # "path":"/999_App_Test/ds1/01587.json", # "storagePath":"/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/9/k/Hs/...json", # "meta":{ # "ext":"json", # "mime":"application/json", # "size":252 # }, # "createdAt":"2021-01-11T09:04:18.099Z", # "updatedAt":"2021-01-11T09:04:18.099Z", # "hash":"La9+XtF2+cTlAqUE/I72e/xS12LqyH1+z<3T+SgD4CTU=", # "fullStorageUrl":"http://supervisely.com/h5un6l2bnaz1vj8a9qgms4-public/teams_storage/8/9/k/Hs/...json", # "teamId":8, # "name":"01587.json" # } # ] # ..or as FileInfo with attributes: files = api.file.list(team_id, file_path, return_type='fileinfo') file = files[0] print(file.id) # Output: 7660 print(files) # Output: [ # FileInfo(team_id=8, id=7660, user_id=7, name='00135.json', hash='z7Wv1a7WI... # FileInfo(team_id=8, id=7661, user_id=7, name='01587.json', hash='La9+XtF2+... # ]
-
list2(team_id, path, recursive=
True)[source]¶ Disclaimer: Method is not recommended. Use api.file.list instead
List of files in the Team Files.
- Parameters:
- Returns:
List of all Files with information. See class info_sequence
- Return type:
List[
FileInfo]- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() team_id = 9 file_path = "/My_App_Test/" files = api.file.list2(team_id, file_path) print(files) # Output: [ # FileInfo(team_id=9, id=18421, user_id=8, name='5071_3734_mot_video_002.tar.gz', hash='+0nrNoDjBxxJA... # FileInfo(team_id=9, id=18456, user_id=8, name='5164_4218_mot_video_bitmap.tar.gz', hash='fwtVI+iptY... # FileInfo(team_id=9, id=18453, user_id=8, name='all_vars.tar', hash='TVkUE+K1bnEb9QrdEm9akmHm/QEWPJK... # ]
-
list_on_agent(team_id, path, recursive=
True, return_type='dict')[source]¶ List of files in the Team Files.
- Parameters:
- Returns:
List of all Files with information.
- Return type:
List[Union[Dict,
FileInfo]]
-
listdir(team_id, path, recursive=
False)[source]¶ List dirs and files in the directiry with given path.
- Parameters:
- Returns:
List of paths
- Return type:
List[str]- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() team_id = 8 path = "/999_App_Test/" files = api.file.listdir(team_id, path) print(files) # Output: ["/999_App_Test/ds1", "/999_App_Test/image.png"]
-
load_dotenv_from_teamfiles(remote_path=
None, team_id=None, override=False)[source]¶ Loads .env file from Team Files into environment variables. If remote_path or team_id is not specified, it will be taken from environment variables.
- Parameters:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() api.file.load_dotenv_from_teamfiles() # All variables from .env file are loaded into environment variables.
- remove(team_id, path)[source]¶
Removes a file from the Team Files. If the specified path is a directory, the entire directory (including all recursively included files) will be removed.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() api.file.remove(8, "/999_App_Test/ds1/01587.json") # remove file api.file.remove(8, "/999_App_Test/ds1/") # remove folder
-
remove_batch(team_id, paths, progress_cb=
None, batch_size=1000)[source]¶ Removes list of files from Team Files.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() paths_to_del = [ "/999_App_Test/ds1/01587.json", "/999_App_Test/ds1/01588.json", "/999_App_Test/ds1/01587.json" ] api.file.remove_batch(8, paths_to_del)
-
remove_dir(team_id, path, silent=
False)[source]¶ Removes folder from Team Files.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() api.file.remove_dir(8, "/999_App_Test/ds1/")
- remove_file(team_id, path)[source]¶
Removes file from Team Files.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() api.file.remove_file(8, "/999_App_Test/ds1/01587.json")
- rename(old_name, new_name)[source]¶
Renames file in Team Files
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() # NotImplementedError('Method is not supported')
-
upload(team_id, src, dst, progress_cb=
None)[source]¶ Upload File to Team Files.
- Parameters:
- Returns:
Information about uploaded file.
- Return type:
FileInfo- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() src_path = "/home/admin/Downloads/01587.json" dst_remote_path = "/999_App_Test/ds1/01587.json" api.file.upload(8, src_path, dst_remote_path)
-
async upload_async(team_id, src, dst, semaphore=
None, progress_cb=None, progress_cb_type='size')[source]¶ Upload file from local path to Team Files asynchronously.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- src : str¶
Local path to file.
- dst : str¶
Path to save file in Team Files.
- semaphore : asyncio.Semaphore, optional¶
Semaphore for limiting the number of simultaneous uploads.
- progress_cb : tqdm or callable, optional¶
Function for tracking download progress.
- progress_cb_type : Literal["number", "size"], optional¶
Type of progress callback. Can be “number” or “size”. Default is “size”.
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_file = "/path/to/local/file/01587.json" path_to_save = "/files/01587.json" loop = sly.utils.get_or_create_event_loop() loop.run_until_complete( api.file.upload_async(8, path_to_file, path_to_save) )
-
upload_bulk(team_id, src_paths, dst_paths, progress_cb=
None)[source]¶ Upload Files to Team Files.
- Parameters:
- Returns:
Information about uploaded files.
- Return type:
List[
FileInfo]- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() src_paths = ["/home/admin/Downloads/01587.json", "/home/admin/Downloads/01588.json","/home/admin/Downloads/01589.json"] dst_remote_paths = ["/999_App_Test/ds1/01587.json", "/999_App_Test/ds1/01588.json", "/999_App_Test/ds1/01589.json"] api.file.upload_bulk(8, src_paths, dst_remote_paths)
-
async upload_bulk_async(team_id, src_paths, dst_paths, semaphore=
None, progress_cb=None, progress_cb_type='size', enable_fallback=True)[source]¶ Upload multiple files from local paths to Team Files asynchronously.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- src_paths : List[str]¶
List of local paths to files.
- dst_paths : List[str]¶
List of paths to save files in Team Files.
- semaphore : asyncio.Semaphore, optional¶
Semaphore for limiting the number of simultaneous uploads.
- progress_cb : tqdm or callable, optional¶
Function for tracking download progress.
- progress_cb_type : Literal["number", "size"], optional¶
Type of progress callback. Can be “number” or “size”. Default is “size”.
- enable_fallback : bool, optional¶
If True, the method will fallback to synchronous upload if an error occurs.
- Returns:
None
- Return type:
None
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() paths_to_files = [ "/path/to/local/file/01587.json", "/path/to/local/file/01588.json", "/path/to/local/file/01589.json" ] paths_to_save = [ "/files/01587.json", "/files/01588.json", "/files/01589.json" ] loop = sly.utils.get_or_create_event_loop() loop.run_until_complete( api.file.upload_bulk_async(8, paths_to_files, paths_to_save) )
-
upload_bulk_fast(team_id, src_paths, dst_paths, semaphore=
None, progress_cb=None, progress_cb_type='size', enable_fallback=True)[source]¶ Upload multiple files from local paths to Team Files in fast mode. Files are uploaded asynchronously. If an error occurs, the method will fallback to synchronous upload.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- src_paths : List[str]¶
List of local paths to files.
- dst_paths : List[str]¶
List of paths to save files in Team Files.
- semaphore : asyncio.Semaphore, optional¶
Semaphore for limiting the number of simultaneous uploads.
- progress_cb : tqdm or callable, optional¶
Function for tracking download progress.
- progress_cb_type : Literal["number", "size"], optional¶
Type of progress callback. Can be “number” or “size”. Default is “size”. “size” is used to track the number of transferred bytes. “number” is used to track the number of transferred files.
- enable_fallback : bool, optional¶
If True, the method will fallback to synchronous upload if an error occurs.
- Returns:
None
- Return type:
None
-
upload_directory(team_id, local_dir, remote_dir, change_name_if_conflict=
True, progress_size_cb=None, replace_if_conflict=False)[source]¶ Upload Directory to Team Files from local path.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- local_dir : str¶
Path to local Directory.
- remote_dir : str¶
Path to Directory in Team Files.
- change_name_if_conflict : bool, optional¶
Checks if given name already exists and adds suffix to the end of the name.
- progress_size_cb : Progress, optional¶
Function for tracking download progress.
- Returns:
Path to Directory in Team Files
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_dir = "/My_App_Test/ds1" local_path = "/home/admin/Downloads/My_local_test" api.file.upload_directory(9, local_path, path_to_dir)
-
async upload_directory_async(team_id, local_dir, remote_dir, change_name_if_conflict=
True, progress_size_cb=None, replace_if_conflict=False, enable_fallback=True)[source]¶ Upload Directory to Team Files from local path. Files are uploaded asynchronously.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- local_dir : str¶
Path to local Directory.
- remote_dir : str¶
Path to Directory in Team Files.
- change_name_if_conflict : bool, optional¶
Checks if given name already exists and adds suffix to the end of the name.
- progress_size_cb : Progress, optional¶
Function for tracking download progress.
- replace_if_conflict : bool, optional¶
If True, replace existing dir.
- enable_fallback : bool, optional¶
If True, the method will fallback to synchronous upload if an error occurs.
- Returns:
Path to Directory in Team Files
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() path_to_dir = "/999_App_Test/ds1" local_path = "/path/to/local/folder" api.file.upload_directory(8, local_path, path_to_dir)
-
upload_directory_fast(team_id, local_dir, remote_dir, change_name_if_conflict=
True, progress_cb=None, replace_if_conflict=False, enable_fallback=True)[source]¶ Upload Directory to Team Files from local path in fast mode. Files are uploaded asynchronously. If an error occurs, the method will fallback to synchronous upload.
- Parameters:
- team_id : int¶
Team ID in Supervisely.
- local_dir : str¶
Path to local Directory.
- remote_dir : str¶
Path to Directory in Team Files.
- change_name_if_conflict : bool, optional¶
Checks if given name already exists and adds suffix to the end of the name.
- progress_cb : Progress, optional¶
Function for tracking download progress in bytes.
- replace_if_conflict : bool, optional¶
If True, replace existing dir.
- enable_fallback : bool, optional¶
If True, the method will fallback to synchronous upload if an error occurs.
- Returns:
Path to Directory in Team Files
- Return type: