def transformation(transformation, **options): uri = ["transformations"] params = only(options, "next_cursor", "max_results") params["transformation"] = utils.build_single_eager(transformation) return call_api("get", uri, params, **options)
def create_upload_preset(**options): uri = ["upload_presets"] params = utils.build_upload_params(**options) params = utils.cleanup_params(params) params.update( only(options, "unsigned", "disallow_public_id", "name", "live")) return call_api("post", uri, params, **options)
def delete_derived_by_transformation(public_ids, transformations, resource_type='image', type='upload', invalidate=None, **options): """Delete derived resources of public ids, identified by transformations :param public_ids: the base resources :type public_ids: list of str :param transformations: the transformation of derived resources, optionally including the format :type transformations: list of (dict or str) :param type: The upload type :type type: str :param resource_type: The type of the resource: defaults to "image" :type resource_type: str :param invalidate: (optional) True to invalidate the resources after deletion :type invalidate: bool :return: a list of the public ids for which derived resources were deleted :rtype: dict """ uri = ["resources", resource_type, type] if not isinstance(public_ids, list): public_ids = [public_ids] params = {"public_ids": public_ids, "transformations": utils.build_eager(transformations), "keep_original": True} if invalidate is not None: params['invalidate'] = invalidate return call_api("delete", uri, params, **options)
def resources_by_ids(public_ids, **options): resource_type = options.pop("resource_type", "image") upload_type = options.pop("type", "upload") uri = ["resources", resource_type, upload_type] params = dict(only(options, "tags", "moderations", "context"), public_ids=public_ids) return call_api("get", uri, params, **options)
def update(public_id, **options): resource_type = options.pop("resource_type", "image") upload_type = options.pop("type", "upload") uri = ["resources", resource_type, upload_type, public_id] params = only(options, "moderation_status", "raw_convert", "quality_override", "ocr", "categorization", "detection", "similarity_search", "background_removal", "notification_url") if "tags" in options: params["tags"] = ",".join(utils.build_array(options["tags"])) if "face_coordinates" in options: params["face_coordinates"] = utils.encode_double_array( options.get("face_coordinates")) if "custom_coordinates" in options: params["custom_coordinates"] = utils.encode_double_array( options.get("custom_coordinates")) if "context" in options: params["context"] = utils.encode_context(options.get("context")) if "auto_tagging" in options: params["auto_tagging"] = str(options.get("auto_tagging")) if "access_control" in options: params["access_control"] = utils.json_encode( utils.build_list_of_dicts(options.get("access_control"))) return call_api("post", uri, params, **options)
def resource(public_id, **options): resource_type = options.pop("resource_type", "image") upload_type = options.pop("type", "upload") uri = ["resources", resource_type, upload_type, public_id] params = only(options, "exif", "faces", "colors", "image_metadata", "cinemagraph_analysis", "pages", "phash", "coordinates", "max_results", "quality_analysis", "derived_next_cursor") return call_api("get", uri, params, **options)
def resources(**options): resource_type = options.pop("resource_type", "image") upload_type = options.pop("type", None) uri = ["resources", resource_type] if upload_type: uri.append(upload_type) params = only(options, "next_cursor", "max_results", "prefix", "tags", "context", "moderations", "direction", "start_at") return call_api("get", uri, params, **options)
def create_transformation(name, definition, **options): uri = ["transformations"] params = { "name": name, "transformation": utils.build_single_eager(definition) } return call_api("post", uri, params, **options)
def delete_folder(path, **options): """Deletes folder Deleted folder must be empty, but can have descendant empty sub folders :param path: The folder to delete :param options: Additional options :rtype: Response """ return call_api("delete", ["folders", path], {}, **options)
def update_transformation(transformation, **options): uri = ["transformations"] updates = only(options, "allowed_for_strict") if "unsafe_update" in options: updates["unsafe_update"] = transformation_string(options.get("unsafe_update")) updates["transformation"] = utils.build_single_eager(transformation) return call_api("put", uri, updates, **options)
def resource_by_asset_id(asset_id, **options): """ Returns the details of the specified asset and all its derived assets by asset id. :param asset_id: The Asset ID of the asset :type asset_id: string :param options: Additional options :type options: dict, optional :return: Resource (asset) of a specific asset_id :rtype: Response """ uri = ["resources", asset_id] params = _prepare_asset_details_params(**options) return call_api("get", uri, params, **options)
def resources_by_asset_ids(asset_ids, **options): """Retrieves the resources (assets) indicated in the asset IDs. This method does not return deleted assets even if they have been backed up. See: `Get resources by context API reference <https://cloudinary.com/documentation/admin_api#get_resources>`_ :param asset_ids: The requested asset IDs. :type asset_ids: list[str] :param options: Additional options :type options: dict, optional :return: Resources (assets) as indicated in the asset IDs :rtype: Response """ uri = ["resources", 'by_asset_ids'] params = dict(only(options, "tags", "moderations", "context"), asset_ids=asset_ids) return call_api("get", uri, params, **options)
def usage(**options): """Get account usage details. Get a report on the status of your Cloudinary account usage details, including storage, credits, bandwidth, requests, number of resources, and add-on usage. Note that numbers are updated periodically. See: `Get account usage details <https://cloudinary.com/documentation/admin_api#get_account_usage_details>`_ :param options: Additional options :type options: dict, optional :return: Detailed usage information :rtype: Response """ date = options.pop("date", None) uri = ["usage"] if date: if isinstance(date, datetime.date): date = utils.encode_date_to_usage_api_format(date) uri.append(date) return call_api("get", uri, {}, **options)
def resources_by_context(key, value=None, **options): """Retrieves resources (assets) with a specified context key. This method does not return deleted assets even if they have been backed up. See: `Get resources by context API reference <https://cloudinary.com/documentation/admin_api#get_resources_by_context>`_ :param key: Only assets with this context key are returned :type key: str :param value: Only assets with this value for the context key are returned :type value: str, optional :param options: Additional options :type options: dict, optional :return: Resources (assets) with a specified context key :rtype: Response """ resource_type = options.pop("resource_type", "image") uri = ["resources", resource_type, "context"] params = only(options, "next_cursor", "max_results", "tags", "context", "moderations", "direction") params["key"] = key if value is not None: params["value"] = value return call_api("get", uri, params, **options)
def subfolders(of_folder_path, **options): return call_api("get", ["folders", of_folder_path], only(options, "next_cursor", "max_results"), **options)
def upload_preset(name, **options): uri = ["upload_presets", name] return call_api("get", uri, only(options, "max_results"), **options)
def resources_by_moderation(kind, status, **options): resource_type = options.pop("resource_type", "image") uri = ["resources", resource_type, "moderations", kind, status] params = only(options, "next_cursor", "max_results", "tags", "context", "moderations", "direction") return call_api("get", uri, params, **options)
def create_streaming_profile(name, **options): uri = ["streaming_profiles"] params = __prepare_streaming_profile_params(**options) params["name"] = name return call_api('POST', uri, params, **options)
def update_streaming_profile(name, **options): uri = ["streaming_profiles", name] params = __prepare_streaming_profile_params(**options) return call_api('PUT', uri, params, **options)
def get_streaming_profile(name, **options): uri = ["streaming_profiles", name] return call_api('GET', uri, {}, **options)
def delete_streaming_profile(name, **options): uri = ["streaming_profiles", name] return call_api('DELETE', uri, {}, **options)
def create_upload_mapping(name, **options): uri = ["upload_mappings"] params = dict(folder=name) params.update(only(options, "template")) return call_api("post", uri, params, **options)
def list_streaming_profiles(**options): uri = ["streaming_profiles"] return call_api('GET', uri, {}, **options)
def delete_upload_mapping(name, **options): uri = ["upload_mappings"] params = dict(folder=name) return call_api("delete", uri, params, **options)
def resource_types(**options): return call_api("get", ["resources"], {}, **options)
def upload_mappings(**options): uri = ["upload_mappings"] return call_api("get", uri, only(options, "next_cursor", "max_results"), **options)
def delete_upload_preset(name, **options): uri = ["upload_presets", name] return call_api("delete", uri, {}, **options)
def usage(**options): return call_api("get", ["usage"], {}, **options)
def create_folder(path, **options): return call_api("post", ["folders", path], {}, **options)
def root_folders(**options): return call_api("get", ["folders"], only(options, "next_cursor", "max_results"), **options)