Trillo Workbench Python SDK
  • Introduction
    • Sample Example
  • BaseApi (Basic APIs)
  • LogApi (Logging APIs)
  • DSApi (Database APIs)
    • Overview
    • Retrieve APIs
    • Create and Update API
    • Delete APIs
    • Empty Table
    • Sample Functions Using API
  • FuncApi (Function APIs)
  • TaskApi (Task APIs)
  • CacheApi (Memory Cache APIs)
    • Delete APIs
    • Create and Update API
    • Retrieve APIs
  • StorageApi
  • CallLogger (Logging Level APIs)
  • CommandApi
  • OAuth1Api
  • Google Cloud APIs
    • BigQueryApi (BigQuery APIs)
    • GCSApi (Cloud Storage APIs)
    • GCPAuthApi
    • GCPRestApi
    • GCPTokenInfo
  • Metadata API (MetaApi)
    • Create and Update API
    • All Retrieve-Only
  • UMApi (User, Tenant, Roles APIs)
  • HttpApi (HTTP APIs)
  • SFTPApi
  • FileUtil
  • CSVApi
  • EmailApi (Email APIs)
  • DLPApi
  • DocApi
  • FolderApi
  • GCPGenApi
  • Util
Powered by GitBook
On this page
  • asJSONPrettyString
  • convertToResult
  • asJSONString
  • fromJSONString
  • fromJSONStringAsMap
  • saveAsJSONString
  • fromStringToDate
  • fromDateToString
  • genRandomAlphaNum
  • mapByDisplayNames
  • listByDisplayNames
  • deepCopy
  • convertToListOfDict
  • convertToList
  • convertToInt
  • convertToDict
  • convertToBool
  • uidToClassName
  • uidToId
  • uidToIdStr
  • validateJson
  • toPrettyJSONString
  • getCurrentLanguage
  • asUid
  • addObjectByPath
  • removeLeadingChars
  • removeLastCharIfMatches
  • roundDouble
  • urlEncode
  • urlDecode

Util

asJSONPrettyString

Convert an object to a pretty-printed JSON string.

Util.asJSONPrettyString(obj: Any) -> str

Parameters

obj: Object to convert.

Returns

A pretty-printed JSON string representation of the object.

convertToResult

Convert a response to a Result object if possible.

Util.convertToResult(r) -> Result or None

Parameters

r: Response object to convert.

Returns

Result object if conversion is successful, otherwise None.

asJSONString

Convert an object to a JSON string.

Util.asJSONString(obj: Any) -> str

Parameters

obj: Object to convert.

Returns

JSON string representation of the object.

fromJSONString

Convert a JSON string to an object of the specified class.

Util.fromJSONString(json_str: str, cls: Any) -> Any

Parameters

json_str: JSON string to convert.
cls: Class of the object to create.

Returns

Object created from the JSON string

fromJSONStringAsMap

Convert a JSON string to a dictionary.

Util.fromJSONStringAsMap(json_str: str) -> Dict[str, Any]

Parameters

json_str: JSON string to convert.

Returns

Dictionary created from the JSON string.

saveAsJSONString

Save an object as JSON to a file.

Util.saveAsJSONString(file_path: str, obj: Any) -> None

Parameters

file_path: Path of the file to save.
obj: Object to save as JSON.

Returns

None.

fromStringToDate

Convert a string to a datetime object.

Util.fromStringToDate(date, format="%Y-%m-%d %H:%M:%S") -> datetime

Parameters

date: String representing the date.
format: Format of the date string (default is "%Y-%m-%d %H:%M:%S").

Returns

Datetime object.

fromDateToString

Convert a datetime object to a string.

Util.fromDateToString(date: datetime, format: str = "%Y-%m-%d %H:%M:%S") -> str

Parameters

date: Datetime object to convert.
format: Format of the output string (default is "%Y-%m-%d %H:%M:%S").

Returns

String representing the datetime.

genRandomAlphaNum

Generate a random alphanumeric string of specified length.

Util.genRandomAlphaNum(length: int) -> str

Parameters

length: Length of the generated string.

Returns

Random alphanumeric string.

mapByDisplayNames

Map objects by display names.

Util.mapByDisplayNames(input_map: Dict[str, Any], names: List[str], displayNames: List[str]) -> Dict[str, Any]

Parameters

input_map: Input map to process.
names: List of names.
displayNames: List of display names.

Returns

Mapped dictionary.

listByDisplayNames

List objects by display names.

Util.listByDisplayNames(input_list: List[Dict[str, Any]], names: List[str], displayNames: List[str]) -> List[Dict[str, Any]]

Parameters

input_list: Input list to process.
names: List of names.
displayNames: List of display names.

Returns

List of dictionaries.

deepCopy

Create a deep copy of a dictionary.

Util.deepCopy(input_map: Dict[str, Any]) -> Dict[str, Any]

Parameters

input_map: Input dictionary to copy.

Returns

Deep copy of the dictionary.

convertToListOfDict

Convert input object to a list of dictionaries.

Util.convertToListOfDict(input_object) -> List[Dict[str, Any]]

Parameters

input_object: Input object to convert.

Returns

List of dictionaries.

convertToList

Convert input object to a list.

Util.convertToList(input_object) -> List[Any]

Parameters

input_object: Input object to convert.

Returns

List.

convertToInt

Convert input object to an integer.

Util.convertToInt(input_object) -> int

Parameters

input_object: Input object to convert.

Returns

Integer.

convertToDict

Convert input object to a dictionary.

Util.convertToDict(input_object) -> Dict[str, Any]

Parameters

input_object: Input object to convert.

Returns

Dictionary.

convertToBool

Convert input object to a boolean.

Util.convertToBool(input_object) -> bool

Parameters

input_object: Input object to convert.

Returns

Boolean.

uidToClassName

Extract class name from UID.

Util.uidToClassName(uid) -> str or None

Parameters

uid: UID string.

Returns

Class name extracted from the UID.

uidToId

Extract ID from UID.

Util.uidToId(uid) -> int

Parameters

uid: UID string.

Returns

ID extracted from the UID.

uidToIdStr

Extract ID as string from UID.

Util.uidToIdStr(uid) -> str or None

Parameters

uid: UID string.

Returns

ID as string extracted from the UID.

validateJson

Validate JSON string.

Util.validateJson(json_str) -> bool

Parameters

json_str: JSON string to validate.

Returns

True if valid JSON, False otherwise.

toPrettyJSONString

Convert JSON string to pretty-printed JSON string.

Util.toPrettyJSONString(json_str) -> str

Parameters

json_str: JSON string to convert.

Returns

Pretty-printed JSON string.

getCurrentLanguage

Get the current language.

Util.getCurrentLanguage() -> str

Parameters

None.

Returns

Current language.

asUid

Convert class name and ID to UID.

Util.asUid(className, _id=None) -> str

Parameters

className: Class name.
_id: ID (optional).

Returns

UID.

addObjectByPath

Add object to dictionary by path.

Util.addObjectByPath(map_, path, value)

Parameters

map_: Dictionary to add the object to.
path: Path to the object.
value: Object to add.

Returns

None.

removeLeadingChars

Remove leading characters from a string.

Util.removeLeadingChars(s, c) -> str

Parameters

s: Input string.
c: Character to remove.

Returns

String with leading characters removed.

removeLastCharIfMatches

Remove last character from a string if it matches a specified character.

Util.removeLastCharIfMatches(s, c) -> str

Parameters

s: Input string.
c: Character to match.

Returns

String with last character removed if it matches the specified character.

roundDouble

Round a floating-point number to specified decimal places.

Util.roundDouble(value: float, places: int) -> float

Parameters

value: Floating-point number to round.
places: Number of decimal places.

Returns

Rounded floating-point number.

urlEncode

URL-encode a string.

Util.urlEncode(s: str) -> str

Parameters

s: String to encode.

Returns

URL-encoded string.

urlDecode

URL-decode a string.

Util.urlDecode(s: str) -> str

Parameters

s: String to decode.

Returns

URL-decoded string.
PreviousGCPGenApi

Last updated 1 year ago