Coretex
coretex.coretex.sample.custom_sample.custom_sample.CustomSample Class Reference
Inheritance diagram for coretex.coretex.sample.custom_sample.custom_sample.CustomSample:
coretex.coretex.sample.network_sample.NetworkSample coretex.coretex.sample.custom_sample.custom_sample_data.CustomSampleData coretex.coretex.sample.custom_sample.local_custom_sample.LocalCustomSample coretex.coretex.sample.sample.Sample coretex.coretex.sample.local_sample.LocalSample coretex.coretex.sample.custom_sample.custom_sample_data.CustomSampleData coretex.coretex.sample.sample.Sample

Public Member Functions

Optional[Self] createCustomSample (cls, str name, int datasetId, Union[Path, str] filePath, Optional[str] mimeType=None)
 
- Public Member Functions inherited from coretex.coretex.sample.network_sample.NetworkSample
str path (self)
 
str zipPath (self)
 
bool download (self, bool ignoreCache=False)
 
- Public Member Functions inherited from coretex.coretex.sample.sample.Sample
None unzip (self, bool ignoreCache=False)
 
Path joinPath (self, Union[Path, str] other)
 
- Public Member Functions inherited from coretex.coretex.sample.custom_sample.local_custom_sample.LocalCustomSample
CustomSampleData load (self)
 
- Public Member Functions inherited from coretex.coretex.sample.local_sample.LocalSample
str path (self)
 
str zipPath (self)
 
bool download (self, bool ignoreCache=False)
 

Detailed Description

    Represents the custom Sample object from Coretex.ai\n
    Custom samples are used when working with Other Task\n
    Custom sample must be an archive

Definition at line 28 of file custom_sample.py.

Member Function Documentation

◆ createCustomSample()

Optional[Self] coretex.coretex.sample.custom_sample.custom_sample.CustomSample.createCustomSample (   cls,
str  name,
int  datasetId,
Union[Path, str]  filePath,
Optional[str]   mimeType = None 
)
    Creates a new custom sample with specified properties\n
    For creating custom sample, sample must be an archive

    Parameters
    ----------
    name : str
sample name
    datasetId : int
id of dataset to which the sample will be added
    filePath : str
path to the sample
    mimeType : Optional[str]
mime type of the file, if None mime type guessing will be performed

    Returns
    -------
    Optional[Self] -> The created sample object or None if creation failed

    Raises
    ------
    NetworkRequestError, ValueError -> if some kind of error happened during
    the upload of the provided file

    Example
    -------
    >>> from coretex import CustomSample
    \b
    >>> sample = CustomSample.createCustomSample("name", 1023, "path/to/file")
    >>> if sample is None:
    print("Failed to create custom sample")

Definition at line 40 of file custom_sample.py.

40  def createCustomSample(
41  cls,
42  name: str,
43  datasetId: int,
44  filePath: Union[Path, str],
45  mimeType: Optional[str] = None
46  ) -> Optional[Self]:
47  """
48  Creates a new custom sample with specified properties\n
49  For creating custom sample, sample must be an archive
50 
51  Parameters
52  ----------
53  name : str
54  sample name
55  datasetId : int
56  id of dataset to which the sample will be added
57  filePath : str
58  path to the sample
59  mimeType : Optional[str]
60  mime type of the file, if None mime type guessing will be performed
61 
62  Returns
63  -------
64  Optional[Self] -> The created sample object or None if creation failed
65 
66  Raises
67  ------
68  NetworkRequestError, ValueError -> if some kind of error happened during
69  the upload of the provided file
70 
71  Example
72  -------
73  >>> from coretex import CustomSample
74  \b
75  >>> sample = CustomSample.createCustomSample("name", 1023, "path/to/file")
76  >>> if sample is None:
77  print("Failed to create custom sample")
78  """
79 
80  uploadSession = ChunkUploadSession(MAX_CHUNK_SIZE, filePath, mimeType)
81  uploadId = uploadSession.run()
82 
83  parameters = [
84  ("name", (None, name)),
85  ("dataset_id", (None, datasetId)),
86  ("file_id", (None, uploadId))
87  ]
88 
89  # files parameter can accept parameters that are not files, this way we can
90  # send form-data requests without actual files
91  response = networkManager.genericUpload("session/import", files = parameters)
92  if response.hasFailed():
93  return None
94 
95  return cls.decode(response.json)

The documentation for this class was generated from the following file: