SDS Client | spectrumx.client.Client
spectrumx.client.Client
Client(
host: None | str,
*,
env_file: Path | None = None,
env_config: Mapping[str, Any] | None = None,
verbose: bool = False,
log_file: Path | None = None,
)
Instantiates an SDS client.
Methods:
| Name | Description |
|---|---|
authenticate |
Authenticate the client. |
delete_file |
Deletes a file from SDS by its UUID. |
detach_file_from_datasets |
Detach a file from all datasets it is associated with (owner-only). |
download |
Downloads files from SDS. |
download_dataset |
Downloads files in a dataset using the existing download infrastructure. |
download_file |
Downloads a file from SDS: metadata and maybe contents. |
download_single_file |
Download a single file and return the result. |
get_dataset |
Fetch dataset metadata, captures, and artifact files from SDS. |
get_file |
Get a file instance by its ID. Only metadata is downloaded from SDS. |
list_dataset_artifact_files |
List dataset artifact files (not the full download manifest). |
list_dataset_captures |
List captures for a dataset (raw dicts; composite payloads supported). |
list_files |
Lists files in a given SDS path. |
upload |
Uploads a file or directory to SDS. |
upload_capture |
Uploads a local directory and creates a capture using those files. |
upload_file |
Uploads a file to SDS. |
upload_multichannel_drf_capture |
Uploads a capture with multiple channels by running |
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
Base URL for the client. |
base_url_no_port |
str
|
Base URL without the port. |
config |
SDSConfig
|
The client configuration. |
dry_run |
bool
|
When in dry run mode, no SDS requests are made and files are not written. |
gateway |
GatewayClient
|
Underlying gateway client (for tests and advanced HTTP access). |
verbose |
bool
|
When True, shows verbose output. |
Source code in spectrumx/client.py
Attributes
dry_run
property
writable
When in dry run mode, no SDS requests are made and files are not written.
gateway
property
Underlying gateway client (for tests and advanced HTTP access).
Methods:
authenticate
Authenticate the client.
Source code in spectrumx/client.py
delete_file
Deletes a file from SDS by its UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_uuid
|
UUID4 | str
|
The UUID of the file to delete. |
required |
Returns: True if the file was deleted successfully, or if in dry run mode (simulating success). Raises: SDSError: If the file couldn't be deleted.
Source code in spectrumx/client.py
detach_file_from_datasets
Detach a file from all datasets it is associated with (owner-only).
download
download(
*,
from_sds_path: PurePosixPath | Path | str | None = None,
start_time: datetime | None = None,
end_time: datetime | None = None,
to_local_path: Path | str,
files_to_download: DownloadFileSource | None = None,
skip_contents: bool = False,
overwrite: bool = False,
verbose: bool = True,
) -> list[Result[File]]
Downloads files from SDS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_sds_path
|
PurePosixPath | Path | str | None
|
The virtual directory on SDS to download files from. |
None
|
start_time
|
datetime | None
|
The start time to filter DRF capture files by |
None
|
end_time
|
datetime | None
|
The end time to filter DRF capture files by |
None
|
to_local_path
|
Path | str
|
The local path to save the downloaded files to. |
required |
files_to_download
|
DownloadFileSource | None
|
A paginator or list (in dry run mode) of files to download. If not provided, all files in the directory will be downloaded. |
None
|
skip_contents
|
bool
|
When True, only the metadata is downloaded. |
False
|
overwrite
|
bool
|
Whether to overwrite existing local files. |
False
|
verbose
|
bool
|
Show a progress bar. |
True
|
Returns: A list of results for each file discovered and downloaded.
Source code in spectrumx/client.py
download_dataset
download_dataset(
*,
dataset_uuid: UUID4 | str,
to_local_path: Path | str,
capture_uuids: Collection[UUID4 | str] | None = None,
top_level_dirs: Collection[PurePosixPath | Path | str]
| None = None,
artifacts_only: bool = False,
skip_contents: bool = False,
overwrite: bool = False,
verbose: bool = True,
) -> list[Result[File]]
Downloads files in a dataset using the existing download infrastructure.
This approach uses the get_dataset_files endpoint to get a paginated list of File objects and then uses the existing download() method with files_to_download parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_uuid
|
UUID4 | str
|
The UUID of the dataset to download. |
required |
to_local_path
|
Path | str
|
The local path to save the downloaded files to. |
required |
capture_uuids
|
Collection[UUID4 | str] | None
|
If set, only files linked to at least one of these capture UUIDs are downloaded (dataset artifacts with no capture are excluded). |
None
|
top_level_dirs
|
Collection[PurePosixPath | Path | str] | None
|
If set, only files whose |
None
|
artifacts_only
|
bool
|
If set, only return artifact files (not capture-linked files). |
False
|
skip_contents
|
bool
|
When True, only the metadata is downloaded. |
False
|
overwrite
|
bool
|
Whether to overwrite existing local files. |
False
|
verbose
|
bool
|
Show progress bars and detailed output. |
True
|
If both capture_uuids and top_level_dirs are set, a file is included
when it matches either criterion (enforced on the gateway). In dry run
mode, capture/path filters are ignored because simulated files are not
capture-tagged.
Returns:
| Type | Description |
|---|---|
list[Result[File]]
|
A list of results for each file downloaded. |
Source code in spectrumx/client.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 | |
download_file
download_file(
*,
file_instance: File | None = None,
file_uuid: UUID4 | str | None = None,
to_local_path: Path | str | None = None,
skip_contents: bool = False,
warn_missing_path: bool = True,
progress_callback: Callable[[int], None] | None = None,
) -> File
Downloads a file from SDS: metadata and maybe contents.
Note this function always overwrites the local file, if it exists.
Either file_instance or file_uuid must be provided. When passing
a file_instance, it's recommended to set its local_path attribute,
otherwise the download will create a temporary file on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_instance
|
File | None
|
The file instance to download. |
None
|
file_uuid
|
UUID4 | str | None
|
The UUID of the file to download. |
None
|
to_local_path
|
Path | str | None
|
The local path to save the downloaded file to. |
None
|
skip_contents
|
bool
|
When True, only the metadata is downloaded and no files are created on disk. |
False
|
warn_missing_path
|
bool
|
Show a warning when the download location is undefined. |
True
|
progress_callback
|
Callable[[int], None] | None
|
Optional callable invoked with byte count as data is received from the stream (for progress tracking). |
None
|
Returns: The file instance with updated attributes, or a sample when in dry run.
Source code in spectrumx/client.py
download_single_file
download_single_file(
*,
file_info: File,
to_local_path: Path,
skip_contents: bool,
overwrite: bool,
progress_callback: Callable[[int], None] | None = None,
) -> Result[File]
Download a single file and return the result.
Source code in spectrumx/client.py
get_dataset
get_dataset(dataset_uuid: UUID4 | str) -> Dataset
Fetch dataset metadata, captures, and artifact files from SDS.
get_file
get_file(file_uuid: UUID4 | str) -> File
Get a file instance by its ID. Only metadata is downloaded from SDS.
Note this does not download the file contents from the server. File
instances still need to have their contents downloaded to create
a local copy - see Client.download_file().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_uuid
|
UUID4 | str
|
The UUID of the file to retrieve. |
required |
Returns: The file instance, or a sample file if in dry run mode.
Source code in spectrumx/client.py
list_dataset_artifact_files
List dataset artifact files (not the full download manifest).
Source code in spectrumx/client.py
list_dataset_captures
List captures for a dataset (raw dicts; composite payloads supported).
Source code in spectrumx/client.py
list_files
list_files(
sds_path: PurePosixPath | Path | str,
start_time: datetime | None = None,
end_time: datetime | None = None,
*,
verbose: bool = False,
) -> Paginator[File]
Lists files in a given SDS path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sds_path
|
PurePosixPath | Path | str
|
The virtual directory on SDS to list files from. |
required |
start_time
|
datetime | None
|
Optional inclusive lower time bound for |
None
|
end_time
|
datetime | None
|
Optional inclusive upper time bound; requires |
None
|
verbose
|
bool
|
Show network requests and other info. |
False
|
Returns: A paginator for the files in the given SDS path.
Source code in spectrumx/client.py
upload
upload(
*,
local_path: Path | str,
sds_path: PurePosixPath | Path | str = "/",
verbose: bool = True,
warn_skipped: bool = True,
persist_state: bool = True,
) -> list[Result[File]]
Uploads a file or directory to SDS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
Path | str
|
The local path of the file or directory to upload. |
required |
sds_path
|
PurePosixPath | Path | str
|
The virtual directory on SDS to upload the file to, where '/' is the user root. |
'/'
|
verbose
|
bool
|
Show a progress bar. |
True
|
warn_skipped
|
bool
|
Display warnings for skipped files. |
True
|
persist_state
|
bool
|
Whether to persist upload state for resumption. |
True
|
Source code in spectrumx/client.py
upload_capture
upload_capture(
*,
local_path: Path | str,
sds_path: PurePosixPath | Path | str = "/",
capture_type: CaptureType,
index_name: str = "",
channel: str | None = None,
scan_group: str | None = None,
name: str | None = None,
verbose: bool = True,
warn_skipped: bool = False,
raise_on_error: bool = True,
persist_state: bool = True,
) -> Capture | None
Uploads a local directory and creates a capture using those files.
This method effectively combines Client.upload() and
Client.captures.create_capture() into one call. For a more fine-grained
control, call each method separately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
Path | str
|
The local path of the directory to upload. |
required |
sds_path
|
PurePosixPath | Path | str
|
The virtual directory on SDS to upload the file to. |
'/'
|
capture_type
|
CaptureType
|
One of |
required |
index_name
|
str
|
The SDS index name. Leave empty to automatically select. |
''
|
channel
|
str | None
|
(For Digital-RF) the DRF channel name to index. |
None
|
scan_group
|
str | None
|
(For RadioHound) UUIDv4 that groups RH files. |
None
|
name
|
str | None
|
Optional custom name for the capture. |
None
|
verbose
|
bool
|
Show progress bar and failure messages, if any. |
True
|
raise_on_error
|
bool
|
When True, raises an exception if any file upload fails. If False, the method will return None and log the errors. |
True
|
persist_state
|
bool
|
Whether to persist upload state for resumption. |
True
|
Returns:
The created capture object when all operations succeed.
Raises:
When raise_on_error is True.
FileError: If any file upload fails.
CaptureError: If the capture creation fails.
Source code in spectrumx/client.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 | |
upload_file
upload_file(
*,
local_file: File | Path | str,
sds_path: PurePosixPath | Path | str = "/",
) -> File
Uploads a file to SDS.
If the file instance passed already has a directory set, sds_path will
be prepended. E.g. given:
sds_path = 'baz'; and
local_file.directory = 'foo/bar/', then:
The file will be uploaded to baz/foo/bar/ (under the user root in SDS) and
the returned file instance will have its directory attribute updated
to match this new path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_file
|
File | Path | str
|
The local file to upload. |
required |
sds_path
|
PurePosixPath | Path | str
|
The virtual directory on SDS to upload the file to. |
'/'
|
Returns: The file instance with updated attributes, or a sample when in dry run.
Source code in spectrumx/client.py
upload_multichannel_drf_capture
upload_multichannel_drf_capture(
*,
local_path: Path | str,
sds_path: PurePosixPath | Path | str = "/",
channels: list[str],
verbose: bool = True,
warn_skipped: bool = False,
raise_on_error: bool = True,
persist_state: bool = True,
) -> list[Capture] | None
Uploads a capture with multiple channels by running upload
once for the whole directory. Then, it creates a capture for each channel.
Note: This method is only for DigitalRF captures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
Path | str
|
The local path of the directory to upload. |
required |
sds_path
|
PurePosixPath | Path | str
|
The virtual directory on SDS to upload the file to. |
'/'
|
channels
|
list[str]
|
The list of channels to create captures for. |
required |
verbose
|
bool
|
Show progress bar and failure messages, if any. |
True
|
warn_skipped
|
bool
|
Display warnings for skipped files. |
False
|
raise_on_error
|
bool
|
When True, raises an exception if any file upload fails. If False, the method will return an empty list or None and log the errors. |
True
|
persist_state
|
bool
|
Whether to persist upload state for resumption. |
True
|
Returns:
A list of captures created for each channel,
or an empty list if any capture creation fails or no channels are provided.
Raises:
When raise_on_error is True.
FileError: If any file upload fails.
Source code in spectrumx/client.py
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 | |