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,
)
Instantiates an SDS client.
Methods:
| Name | Description |
|---|---|
authenticate |
Authenticate the client. |
delete_file |
Deletes a file from SDS by its UUID. |
download |
Downloads files from SDS. |
download_dataset |
Downloads all files in a dataset using the existing download infrastructure. |
download_file |
Downloads a file from SDS: metadata and maybe contents. |
get_file |
Get a file instance by its ID. Only metadata is downloaded from SDS. |
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. |
dry_run |
bool
|
When in dry run mode, no SDS requests are made and files are not written. |
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.
Functions
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
download
download(
*,
from_sds_path: PurePosixPath | Path | str | None = None,
to_local_path: Path | str,
files_to_download: list[File]
| Paginator[File]
| 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
|
to_local_path
|
Path | str
|
The local path to save the downloaded files to. |
required |
files_to_download
|
list[File] | Paginator[File] | 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,
skip_contents: bool = False,
overwrite: bool = False,
verbose: bool = True,
) -> list[Result[File]]
Downloads all 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 |
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
|
Returns: A list of results for each file downloaded.
Source code in spectrumx/client.py
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,
) -> 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
|
Returns: The file instance with updated attributes, or a sample when in dry run.
Source code in spectrumx/client.py
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_files
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 |
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
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
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 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 | |