Logo
3.19.0
  • 1. Getting Started
  • 2. GEMD Data Model
  • 3. Data Extraction
  • 4. AI Engine
  • 5. Formulations Example
  • 6. FAQ
  • 7. API Reference
    • 7.1. citrine package
      • 7.1.1. Subpackages
        • 7.1.1.1. citrine.gemd_queries package
        • 7.1.1.2. citrine.gemtables package
        • 7.1.1.3. citrine.informatics package
        • 7.1.1.4. citrine.jobs package
        • 7.1.1.5. citrine.resources package
        • 7.1.1.6. citrine.seeding package
      • 7.1.2. Submodules
      • 7.1.3. Module contents
Citrine Python
  • 7. citrine
  • 7.1. citrine package
  • 7.1.1.5. citrine.resources package
  • citrine.resources.file_link module
  • View page source

citrine.resources.file_link module

A collection of FileLink objects.

class citrine.resources.file_link.CsvColumnInfo(name: str, bounds: BaseBounds, exact_range_bounds: BaseBounds)

Bases: Serializable

The info for a CSV Column, contains the name, recommended and exact bounds.

classmethod build(data: dict) → Self

Build an instance of this object from given data.

dump() → dict

Dump this instance.

bounds = None

recommended bounds of the column (might include some padding)

Type:

BaseBounds

exact_range_bounds = None

exact bounds of the column

Type:

BaseBounds

name = None

name of the column

Type:

str

class citrine.resources.file_link.FileCollection(*args, session: Session = None, dataset_id: UUID = None, team_id: UUID = None, project_id: UUID | None = None)

Bases: Collection[FileLink]

Represents the collection of all file links associated with a dataset.

build(data: dict) → FileLink

Build an instance of FileLink.

delete(file_link: FileLink)

Delete the file associated with a given FileLink from the database.

Parameters:

file_link (FileLink) – Resource referencing the external file.

download(*, file_link: str | UUID | FileLink, local_path: str | Path)

Download the file associated with a given FileLink to the local computer.

Parameters:
  • file_link (FileLink, str, UUID) – Resource referencing the file.

  • local_path (str, Path) – Path to save file on the local computer. If local_path is a directory, then the filename of this FileLink object will be appended to the path.

get(uid: UUID | str, *, version: UUID | str | int | None = None) → FileLink

Retrieve an on-platform FileLink from its filename or file uuid.

Parameters:
  • uid (Union[UUID, str]) – A representation of the FileLink (Citrine id or file name)

  • version (Optional[UUID, str, int]) – The version, as a UUID or str(UUID) of the version_id or an int or str(int) of the version number. If None, returns the file with the highest version number (most recent).

Returns:

An object with specified scope and uid

Return type:

ResourceType

ingest(files: Iterable[FileLink | Path | str], *, upload: bool = False, raise_errors: bool = True, build_table: bool = False, delete_dataset_contents: bool = False, delete_templates: bool = True, timeout: float = None, polling_delay: float | None = None, project: Project | UUID | str | None = None) → IngestionStatus

[ALPHA] Ingest a set of CSVs and/or Excel Workbooks formatted per the gemd-ingest protocol.

Parameters:
  • files (List[FileLink, Path, or str]) – A list of files from which GEMD objects should be built. A FileLink must contain an absolute URL or a relative path for an on-platform resource. Strings must be resolvable to a FileLink; if resolution fails, an exception is thrown. * If upload is False, an attempt is made to resolve it to an on-platform resource. * If upload is True, resolves locally first, and falls back to on-platform.

  • upload (bool) – If the files are off-platform references, upload them first. Defaults to False, in which case an off-platform resource raises an error. A file is off-platform if it has an absolute URL and that URL is not for the citrine platform. For example, https://example.com/file.csv is off-platform, and would be uploaded to platform and ingested if upload is True.

  • raise_errors (bool) – Whether ingestion errors raise exceptions (vs. simply reported in the results). Default: True

  • build_table (bool) – Whether to trigger a regeneration of the table config and building the table after ingestion. Default: False

  • project (Optional[Project, UUID, or str]) – Which project to use for table build if build_table is True.

  • delete_dataset_contents (bool) – Whether to delete old objects prior to creating new ones. Default: False

  • delete_templates (bool) – Whether to delete old templates if deleting old objects. Default: True

  • timeout (Optional[float]) – Amount of time to wait on the job (in seconds) before giving up. Note that this number has no effect on the underlying job itself, which can also time out server-side.

  • polling_delay (Optional[float]) – How long to delay between each polling retry attempt.

Returns:

The result of the ingestion operation.

Return type:

IngestionStatus

list(*, per_page: int = 100) → Iterator[ResourceType]

Paginate over the elements of the collection.

Leaving page and per_page as default values will yield all elements in the collection, paginating over all available pages.

Parameters:

per_page (int, optional) – Max number of results to return per page. Default is 100. This parameter is used when making requests to the backend service. If the page parameter is specified it limits the maximum number of elements in the response.

Returns:

An iterator that can be used to loop over all the resources in this collection. Use list() to force evaluation of all results into an in-memory list.

Return type:

Iterator[ResourceType]

read(*, file_link: str | UUID | FileLink) → bytes

Read the file associated with a given FileLink.

Parameters:

file_link (FileLink, str, UUID) – Resource referencing the file.

Returns:

The contents of the file.

Return type:

I/O stream

register(model: CreationType) → CreationType

Create a new element of the collection by registering an existing resource.

update(model: CreationType) → CreationType

Update a particular element of the collection.

upload(*, file_path: str | Path, dest_name: str = None) → FileLink

Uploads a file to the dataset.

Parameters:
  • file_path (str, Path) – The path to the file on the local computer.

  • dest_name (str, optional) – The name the file will have after being uploaded. If unspecified, the local name of the file will be used. That is, the file at “/Users/me/diagram.pdf” will be uploaded with the name “diagram.pdf”. File names must be unique within a dataset. If a file is uploaded with the same dest_name as an existing file it will be considered a new version of the existing file.

Returns:

The filename and url of the uploaded object.

Return type:

FileLink

class citrine.resources.file_link.FileLink(filename: str, url: str)

Bases: GEMDResource[FileLink], FileLink

Resource that stores the name and url of an external file.

Parameters:
  • filename (str) – The name of the file.

  • url (str) – URL that can be used to access the file.

access_control_dict() → dict

Return an access control entity representation of this resource. Internal use only.

as_dict() → dict

Dump to a dictionary (useful for interoperability with gemd).

Because of the _key mapping in Property, __dict__’s keys are fundamentally different between gemd.entity.dict_serializable and this class. This means we can’t just use gemd’s as_dict for comparisons.

classmethod build(data: dict) → GEMDSelf

Convert a raw, nested dictionary into Objects.

dump() → dict

Dump this instance.

classmethod from_dict(d: Mapping[str, Any]) → DictSerializableType

Reconstitute the object from a dictionary.

Parameters:

d (dict) – The object as a dictionary of key-value pairs that correspond to the object’s fields.

Returns:

The deserialized object.

Return type:

DictSerializable

classmethod from_path(path: str | Path) → FileLink

Construct a FileLink from a local Path.

created_by = None

Unique uuid4 identifier of this User who loaded this file.

Type:

UUID

created_time = None

Time the file was created on platform.

Type:

datetime

description = None

A human-readable description of the file.

Type:

str

filename = None
mime_type = None

Encoded string representing the type of the file (IETF RFC 2045).

Type:

str

property name

Attribute name is an alias for filename.

size = None

Size in bytes of the file.

Type:

int

skip = {}
typ = 'file_link'
uid = None

Unique uuid4 identifier of this file; consistent across versions.

Type:

UUID

url = None
version = None

Unique uuid4 identifier of this version of this file.

Type:

UUID

version_number = None

How many times this file has been uploaded; files are the “same” if they share a filename and dataset.

Type:

int

class citrine.resources.file_link.FileLinkMeta(name, bases, *args, typ: str = None, skip: Set[str] = frozenset({}), **kwargs)

Bases: DictSerializableMeta

Metaclass for FileLink deserialization.

mro()

Return a type’s method resolution order.

register(subclass)

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

property class_mapping: Dict[str, type]

Return class typ string -> class map for DictSerializable and its descendants.

Note that is actually returns a copy of the internal dict to avoid accidental breakage.

Returns:

The mapping from typ string to class

Return type:

Dict[str, type]

class citrine.resources.file_link.SearchFileFilterTypeEnum(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: BaseEnumeration

The type of the filter used to search for files.

  • SEARCH_BY_NAME:

    Search a file by name in a specific dataset, returns by default the last version or a specific one

  • SEARCH_BY_VERSION_ID:

    Search by a specific file version id

  • SEARCH_BY_DATASET_FILE_ID:

    Search either the last version or a specific version number for a specific dataset file id

capitalize()

Return a capitalized version of the string.

More specifically, make the first character have upper case and the rest lower case.

casefold()

Return a version of the string suitable for caseless comparisons.

center(width, fillchar=' ', /)

Return a centered string of length width.

Padding is done using the specified fill character (default is a space).

count(sub[, start[, end]]) → int

Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.

encode(encoding='utf-8', errors='strict')

Encode the string using the codec registered for encoding.

encoding

The encoding in which to encode the string.

errors

The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

endswith(suffix[, start[, end]]) → bool

Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.

expandtabs(tabsize=8)

Return a copy where all tab characters are expanded using spaces.

If tabsize is not given, a tab size of 8 characters is assumed.

find(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

format(*args, **kwargs) → str

Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).

format_map(mapping) → str

Return a formatted version of S, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).

index(sub[, start[, end]]) → int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

isalnum()

Return True if the string is an alpha-numeric string, False otherwise.

A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

isalpha()

Return True if the string is an alphabetic string, False otherwise.

A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.

isascii()

Return True if all characters in the string are ASCII, False otherwise.

ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

isdecimal()

Return True if the string is a decimal string, False otherwise.

A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.

isdigit()

Return True if the string is a digit string, False otherwise.

A string is a digit string if all characters in the string are digits and there is at least one character in the string.

isidentifier()

Return True if the string is a valid Python identifier, False otherwise.

Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.

islower()

Return True if the string is a lowercase string, False otherwise.

A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.

isnumeric()

Return True if the string is a numeric string, False otherwise.

A string is numeric if all characters in the string are numeric and there is at least one character in the string.

isprintable()

Return True if the string is printable, False otherwise.

A string is printable if all of its characters are considered printable in repr() or if it is empty.

isspace()

Return True if the string is a whitespace string, False otherwise.

A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.

istitle()

Return True if the string is a title-cased string, False otherwise.

In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.

isupper()

Return True if the string is an uppercase string, False otherwise.

A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.

join(iterable, /)

Concatenate any number of strings.

The string whose method is called is inserted in between each given string. The result is returned as a new string.

Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

ljust(width, fillchar=' ', /)

Return a left-justified string of length width.

Padding is done using the specified fill character (default is a space).

lower()

Return a copy of the string converted to lowercase.

lstrip(chars=None, /)

Return a copy of the string with leading whitespace removed.

If chars is given and not None, remove characters in chars instead.

static maketrans()

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

partition(sep, /)

Partition the string into three parts using the given separator.

This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

removeprefix(prefix, /)

Return a str with the given prefix string removed if present.

If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.

removesuffix(suffix, /)

Return a str with the given suffix string removed if present.

If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.

replace(old, new, count=-1, /)

Return a copy with all occurrences of substring old replaced by new.

count

Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are replaced.

rfind(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

rindex(sub[, start[, end]]) → int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

rjust(width, fillchar=' ', /)

Return a right-justified string of length width.

Padding is done using the specified fill character (default is a space).

rpartition(sep, /)

Partition the string into three parts using the given separator.

This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

rsplit(sep=None, maxsplit=-1)

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits. -1 (the default value) means no limit.

Splitting starts at the end of the string and works to the front.

rstrip(chars=None, /)

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

split(sep=None, maxsplit=-1)

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits. -1 (the default value) means no limit.

Splitting starts at the front of the string and works to the end.

Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.

splitlines(keepends=False)

Return a list of the lines in the string, breaking at line boundaries.

Line breaks are not included in the resulting list unless keepends is given and true.

startswith(prefix[, start[, end]]) → bool

Return True if S starts with the specified prefix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. prefix can also be a tuple of strings to try.

strip(chars=None, /)

Return a copy of the string with leading and trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

swapcase()

Convert uppercase characters to lowercase and lowercase characters to uppercase.

title()

Return a version of the string where each word is titlecased.

More specifically, words start with uppercased characters and all remaining cased characters have lower case.

translate(table, /)

Replace each character in the string using the given translation table.

table

Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

upper()

Return a copy of the string converted to uppercase.

zfill(width, /)

Pad a numeric string with zeros on the left, to fill a field of the given width.

The string is never truncated.

DATASET_FILE_ID_SEARCH = 'search_by_dataset_file_id'
NAME_SEARCH = 'search_by_name'
VERSION_ID_SEARCH = 'search_by_version_id'
Previous Next

© Copyright 2019, Citrine Informatics.

Built with Sphinx using a theme provided by Read the Docs.