imednet.cli.utils package¶
CLI utility functions and classes.
Submodules¶
imednet.cli.utils.args module¶
CLI argument parsing utilities.
- class imednet.cli.utils.args.UniqueStoreAction[source]¶
Bases:
ActionStore action that rejects conflicting duplicate flag values.
- imednet.cli.utils.args.add_list_query_args(parser, *, include_filter=True, filter_dest='filter_args', filter_help=None, include_record_data_filter=False)[source]¶
Attach server-side filter, sort, limit, and unbounded flags to a list subparser.
- Parameters:
parser (ArgumentParser) –
include_filter (bool) –
filter_dest (str) –
filter_help (str | None) –
include_record_data_filter (bool) –
- Return type:
None
- imednet.cli.utils.args.add_no_interactive(parser, *, suppress_default=True)[source]¶
Add
--no-interactiveoption to disable interactive UI, spinners, and prompts.- Parameters:
parser (ArgumentParser) –
suppress_default (bool) –
- Return type:
None
- imednet.cli.utils.args.add_output_format(parser)[source]¶
Add common machine response and non-interactive flags to a leaf read command.
- Parameters:
parser (ArgumentParser) –
- Return type:
None
- imednet.cli.utils.args.add_simulation_arg(parser, *, suppress_default=True)[source]¶
Add
--simulationoption to run against offlineSimulationTransportfixtures.- Parameters:
parser (ArgumentParser) –
suppress_default (bool) –
- Return type:
None
- imednet.cli.utils.args.add_study_key_args(parser, *, flag_names=('-s', '--study-key'), include_positional=True, positional_help='The key identifying the study.', flag_help='The key identifying the study.')[source]¶
Register hybrid
--study-keyflag and optional positionalstudy_key.- Parameters:
parser (ArgumentParser) –
flag_names (Sequence[str]) –
include_positional (bool) –
positional_help (str) –
flag_help (str) –
- Return type:
None
- imednet.cli.utils.args.collect_list_items(source, effective_limit)[source]¶
Materialize items from an SDK
list()iterable up toeffective_limit.Detects server-side truncation without issuing an extra page request when backed by
_PaginatedIterator.- Returns:
Tuple of
(items, truncated).- Parameters:
source (Iterable[Any]) –
effective_limit (int | None) –
- Return type:
tuple[list[Any], bool]
- imednet.cli.utils.args.collect_list_items_with_remainder(source, effective_limit)[source]¶
Materialize items up to
effective_limitand return a remainder loader when truncated.Preserves the live
_PaginatedIteratorcursor so subsequent[a]loads drain remaining pages starting at page 1 without re-fetching page 0.- Returns:
Tuple of
(items, truncated, load_remaining).- Parameters:
source (Iterable[Any]) –
effective_limit (int | None) –
- Return type:
tuple[list[Any], bool, Callable[[], list[Any]] | None]
- imednet.cli.utils.args.parse_filter_args(filter_args, *, model=None, allowed_attributes=None, disallow_study_key=False, multi_bound_attributes=None)[source]¶
Parse repeatable CLI
--filterstrings via the shared SPI filter parser.Supports legacy
key=valueequality, Table 2 iMednet comparison operators (<,<=,>,>=,==,!=), compound expressions joined exclusively by;(AND) or,(OR), endpointallowed_attributesallowlists, and Pydanticmodelscalar coercion. Exits with status code1onstderrif validation fails.- Parameters:
filter_args (list[str] | None) –
model (type[Any] | None) –
allowed_attributes (Collection[str] | None) –
disallow_study_key (bool) –
multi_bound_attributes (Collection[str] | None) –
- Return type:
dict[str, Any] | None
- imednet.cli.utils.args.parse_record_data_filter(record_data_filter)[source]¶
Validate a CLI
--record-data-filterstring viavalidate_record_filter.Supports comparison operators including
=~, exclusive;(AND) or,(OR) connectors, and literalnone(case-insensitive) bypass. Exits with status code1onstderrif validation fails.- Parameters:
record_data_filter (str | None) –
- Return type:
str | None
- imednet.cli.utils.args.positive_int(value)[source]¶
Validate and return a strictly positive integer (> 0) for argparse options.
- Parameters:
value (str) –
- Return type:
int
- imednet.cli.utils.args.prepare_list_query(*, filter_args=None, record_data_filter=None, sort=None, limit=None, fetch_all=False, output_format=None, has_output_file=False, no_interactive=False, model=None, allowed_attributes=None, disallow_study_key=False, multi_bound_attributes=None, sort_attributes=None, allow_record_data_sort=None)[source]¶
Validate CLI query options and resolve SDK
list()kwargs and item bound.- Returns:
Tuple of
(request_kwargs, effective_limit).- Parameters:
filter_args (list[str] | None) –
record_data_filter (str | None) –
sort (str | None) –
limit (int | None) –
fetch_all (bool) –
output_format (str | None) –
has_output_file (bool) –
no_interactive (bool) –
model (type[Any] | None) –
allowed_attributes (Collection[str] | None) –
disallow_study_key (bool) –
multi_bound_attributes (Collection[str] | None) –
sort_attributes (Collection[str] | None) –
allow_record_data_sort (bool | None) –
- Return type:
tuple[dict[str, Any], int | None]
- imednet.cli.utils.args.resolve_endpoint_filter_attributes(model)[source]¶
Resolve documented endpoint
FILTER_ATTRIBUTESfor a registered SDK model.- Parameters:
model (type[Any] | None) –
- Return type:
frozenset[str] | None
- imednet.cli.utils.args.resolve_endpoint_sort_metadata(model)[source]¶
Resolve endpoint
(SORT_ATTRIBUTES, ALLOW_RECORD_DATA_SORT)for a registered model.- Parameters:
model (type[Any] | None) –
- Return type:
tuple[frozenset[str] | None, bool]
- imednet.cli.utils.args.resolve_hybrid_study_and_key(parser, args, *, secondary_dest='subject_key', secondary_flag_dest='subject_key_flag')[source]¶
Resolve hybrid positional and flag pairs for
study_keyand a secondary key.- Parameters:
parser (ArgumentParser) –
args (Namespace) –
secondary_dest (str) –
secondary_flag_dest (str) –
- Return type:
tuple[str, str]
- imednet.cli.utils.args.resolve_output_format(output_format=None, *, default='table')[source]¶
Resolve CLI
--formatoption againstIMEDNET_CLI_OUTPUT_FORMAT.- Parameters:
output_format (str | None) –
default (str) –
- Return type:
str
- imednet.cli.utils.args.resolve_study_key(parser, args, *, required=True, missing_error='the following arguments are required: study_key')[source]¶
Resolve hybrid positional
study_keyand--study-keyflag, exiting 2 on conflict.- Parameters:
parser (ArgumentParser) –
args (Namespace) –
required (bool) –
missing_error (str) –
- Return type:
str | None
imednet.cli.utils.commands module¶
Helpers for registering common CLI commands.
- imednet.cli.utils.commands.get_model_value(obj, *keys, default=None)[source]¶
Return the first non-
Nonedictionary entry or object attribute matchingkeys.- Parameters:
obj (Any) –
keys (str) –
default (Any) –
- Return type:
Any
- imednet.cli.utils.commands.register_list_command(parser, attr, name, *, requires_study_key=True, list_help=None, empty_msg=None, summary_fields=None, row_mapper=None, model=None, include_filter=True, filter_dest='filter_args', filter_help=None, multi_bound_attributes=None, export_filename_prefix=None, extra_args_fn=None, extra_kwargs_fn=None, preflight_query=True)[source]¶
Attach a standard
listcommand to parser.- Parameters:
parser (ArgumentParser) –
attr (str) –
name (str) –
requires_study_key (bool) –
list_help (str | None) –
empty_msg (str | None) –
summary_fields (list[str] | None) –
row_mapper (Callable[[Any], dict[str, Any]] | None) –
model (type[Any] | None) –
include_filter (bool) –
filter_dest (str) –
filter_help (str | None) –
multi_bound_attributes (Collection[str] | None) –
export_filename_prefix (str | None) –
extra_args_fn (Callable[[ArgumentParser], None] | None) –
extra_kwargs_fn (Callable[[Namespace], Mapping[str, Any]] | None) –
preflight_query (bool) –
- Return type:
None
imednet.cli.utils.context module¶
CLI context and SDK initialization helpers.
- imednet.cli.utils.context.fetching_status(name, study_key=None)[source]¶
Context manager to show a spinner while fetching data.
- Parameters:
name (str) –
study_key (str | None) –
- Return type:
Iterator[Status]
- imednet.cli.utils.context.get_sdk()[source]¶
Initialize and return the SDK instance using
load_config().- Return type:
- imednet.cli.utils.context.is_offline_schema_dry_run(*, dry_run, schema_source)[source]¶
Return True when
--dry-runis paired with a local--schemapath.- Parameters:
dry_run (bool) –
schema_source (str | None) –
- Return type:
bool
imednet.cli.utils.export module¶
CLI utilities for exporting data to files.
- class imednet.cli.utils.export.Model[source]¶
Bases:
ProtocolProtocol for objects that can be dumped to a dictionary.
- imednet.cli.utils.export.export_list_to_file(items, filename_prefix, output_format, *, study_key=None, mask_phi=True, sdk=None)[source]¶
Export a list of Pydantic models to a CSV or JSON file.
- Parameters:
items (Sequence[Model]) –
filename_prefix (str) –
output_format (str) –
study_key (str | None) –
mask_phi (bool) –
sdk (Any) –
- Return type:
None
- imednet.cli.utils.export.mask_cli_models(items, *, study_key=None, mask_phi=True, sdk=None, custom_phi_fields=None)[source]¶
Return PHI-masked copies of model items for terminal rendering when mask_phi is True.
- Parameters:
items (Sequence[Any]) –
study_key (str | None) –
mask_phi (bool) –
sdk (Any) –
custom_phi_fields (Collection[str] | None) –
- Return type:
list[Any]
- imednet.cli.utils.export.mask_cli_records(items, *, study_key=None, mask_phi=True, sdk=None, custom_phi_fields=None)[source]¶
Return non-flattened PHI-masked copies of
Recorditems when mask_phi is True.- Parameters:
items (Sequence[Any]) –
study_key (str | None) –
mask_phi (bool) –
sdk (Any) –
custom_phi_fields (Collection[str] | None) –
- Return type:
list[Any]
imednet.cli.utils.grid module¶
Interactive keyboard data grid with side panel inspection using curses.
- class imednet.cli.utils.grid.InteractiveDataGrid[source]¶
Bases:
objectCurses-driven scrollable data grid with real-time search and side panel inspection.
- __init__(stdscr, items, fields, label='records', details=None, is_high_contrast=None, status_notice=None, truncated=None, on_load_all=None, entity_kind=None)[source]¶
Initialize the interactive data grid.
- Parameters:
stdscr (Any) – Curses screen window.
items (Sequence[dict[str, Any]]) – List of dictionary rows for table rendering.
fields (list[str]) – Column headers to display.
label (str) – Name of the resource being reviewed (e.g. ‘records’, ‘subjects’).
details (Sequence[Any] | None) – Full domain objects corresponding to each row.
is_high_contrast (bool | None) – Whether high-contrast clinical status mode is active.
status_notice (str | None) – Optional notice displayed when results are truncated/bounded.
truncated (bool | None) – Whether initial rows represent a truncated subset of server items.
on_load_all (Callable[[], Any] | None) – Optional callback draining remaining pages on
[a].entity_kind (str | None) – Optional canonical entity kind (e.g. ‘records’) for side-panel layout.
- Return type:
None
- action_load_all()[source]¶
Load all remaining pages via
on_load_alland re-runfilter_entries.- Return type:
None
- imednet.cli.utils.grid.extract_item_details(detail)[source]¶
Extract metadata and form variables from any domain model or dictionary.
- Parameters:
detail (Any) – A Pydantic model, dictionary, or data object.
- Returns:
A tuple of (metadata_dict, form_variables_dict).
- Return type:
tuple[dict[str, Any], dict[str, Any]]
- imednet.cli.utils.grid.is_interactive_terminal()[source]¶
Determine if stdout and stdin are connected to an active interactive TTY.
- Returns:
True if interactive curses mode should be used, False if output should be emitted as plain tabular text.
- Return type:
bool
- imednet.cli.utils.grid.run_interactive_grid(items, fields, label='records', details=None, is_high_contrast=None, status_notice=None, truncated=None, on_load_all=None, entity_kind=None)[source]¶
Launch the curses interactive data grid.
- Parameters:
items (Sequence[dict[str, Any]]) – List of dictionary rows for table columns.
fields (list[str]) – Column field names.
label (str) – Entity label (e.g. ‘records’, ‘subjects’).
details (Sequence[Any] | None) – Optional list of full domain models for variable inspection.
is_high_contrast (bool | None) – Optional high-contrast mode override.
status_notice (str | None) – Optional truncation/status notice to render in the grid bars.
truncated (bool | None) – Whether initial rows represent a truncated subset of server items.
on_load_all (Callable[[], Any] | None) – Optional callback draining remaining pages on
[a].entity_kind (str | None) – Optional canonical entity kind (e.g. ‘records’) for side-panel layout.
- Returns:
True if the interactive grid ran and exited normally, False if curses could not be initialized.
- Return type:
bool
- imednet.cli.utils.grid.safe_addstr(win, y, x, text, attr=0)[source]¶
Safely write a string to a curses window without boundary exceptions.
- Parameters:
win (Any) – The curses window.
y (int) – Target line row.
x (int) – Target line column.
text (str) – String to render.
attr (int) – Optional curses text attribute.
- Return type:
None
imednet.cli.utils.output module¶
CLI output formatting and display utilities.
- class imednet.cli.utils.output.Console[source]¶
Bases:
objectConsole handling terminal capabilities and live status rendering.
- __init__(stream=None, width=None)[source]¶
Initialize a Console instance.
- Parameters:
stream (Any) – Optional stream destination (defaults to sys.stderr).
width (int | None) – Optional terminal column width override.
- Return type:
None
- is_interactive()[source]¶
Check whether the output stream supports live interactive rendering.
- Return type:
bool
- status(msg, spinner=None, refresh_per_second=12.5, *, announce_non_interactive=True)[source]¶
Create a live status context manager.
- Parameters:
msg (str) –
spinner (str | None) –
refresh_per_second (float) –
announce_non_interactive (bool) –
- Return type:
- property stream: Any¶
Get the active output stream.
- property width: int¶
Get the terminal column width.
- class imednet.cli.utils.output.Status[source]¶
Bases:
objectStatus controller managing live ANSI spinner rendering or static fallback.
- __init__(msg, console, spinner=None, refresh_per_second=12.5, *, announce_non_interactive=True)[source]¶
Initialize a status controller.
- Parameters:
msg (str) – Initial status message.
console (Console) – Console instance managing stream output.
spinner (str | None) – Optional spinner style identifier.
refresh_per_second (float) – Target frame refresh rate.
announce_non_interactive (bool) – Whether to emit the initial message on stderr when entering non-interactive mode.
- Return type:
None
- property lines_rendered: int¶
Get the number of terminal rows occupied by the most recent frame.
- property msg: str¶
Get the current status message.
- imednet.cli.utils.output.clear_line(stream=None, lines=1)[source]¶
Clear the current line(s) and restore terminal cursor on interactive streams.
- Parameters:
stream (Any) – Target output stream (defaults to sys.stderr).
lines (int) – Number of terminal rows to clear.
- Return type:
None
- imednet.cli.utils.output.display_list(items, label, empty_msg=None, fields=None, *, output_format=None, details=None, interactive=None, truncated=False, status_notice=None, on_load_all=None, entity_kind=None, drain_on_fallback=True)[source]¶
Display a human table or one versioned JSON response without progress text.
- Parameters:
items (Sequence[Any]) –
label (str) –
empty_msg (str | None) –
fields (list[str] | None) –
output_format (str | None) –
details (Sequence[Any] | None) –
interactive (bool | None) –
truncated (bool) –
status_notice (str | None) –
on_load_all (Callable[[], Any] | None) –
entity_kind (str | None) –
drain_on_fallback (bool) –
- Return type:
None
- imednet.cli.utils.output.emit_json(items, resource, *, status='complete')[source]¶
Write one complete v1 response after retrieval or execution and serialization.
- Parameters:
items (Sequence[Any]) –
resource (str) –
status (str) –
- Return type:
None
- imednet.cli.utils.output.flush_stdout(stream=None)[source]¶
Flush
stdoutsafely, suppressing broken-pipe disconnects.- Returns:
True when flushed normally, False when downstream closed the pipe early.
- Parameters:
stream (Any) –
- Return type:
bool
- imednet.cli.utils.output.format_job_progress(event, status=None, elapsed=None, bar_width=20)[source]¶
Format a job polling event into a progress bar, state label, and elapsed timer.
- Parameters:
event (JobStatusEvent | Any) – A JobStatusEvent or batch_id string.
status (Any) – Optional JobStatus if event is a batch_id string.
elapsed (float | None) – Optional elapsed seconds if event is a batch_id string.
bar_width (int) – Width of the progress bar in characters.
- Returns:
Formatted string containing progress bar, state label, and elapsed timer.
- Return type:
str
- imednet.cli.utils.output.print_error(*objects, sep=' ', end='\n', file=None, flush=False)[source]¶
Print an error message to sys.stderr safely.
Handles stream safety edge cases: - Writes to sys.stderr by default (or custom file if provided). - Silently handles BrokenPipeError and IOError/OSError if the stream is closed or broken. - Strips ANSI escape sequences when writing to non-interactive (non-tty) streams.
- Parameters:
objects (Any) –
sep (str) –
end (str) –
file (Any) –
flush (bool) –
- Return type:
None
- imednet.cli.utils.output.write_stdout(text='', *, end='\n', stream=None, flush=False)[source]¶
Write
texttostdoutsafely, suppressing broken-pipe disconnects.- Returns:
True when written normally, False when downstream closed the pipe early.
- Parameters:
text (str) –
end (str) –
stream (Any) –
flush (bool) –
- Return type:
bool
imednet.cli.utils.terminal module¶
Centralized terminal capability policy for CLI and SPI extensions.
- imednet.cli.utils.terminal.is_dumb_terminal()[source]¶
Return True when
TERMexplicitly indicates a dumb terminal.- Return type:
bool
- imednet.cli.utils.terminal.is_json_output_mode()[source]¶
Return True when structured JSON output mode is active on stdout.
- Return type:
bool
- imednet.cli.utils.terminal.is_non_interactive()[source]¶
Return True when non-interactive CLI mode has been requested.
- Return type:
bool
- imednet.cli.utils.terminal.is_tty(stream)[source]¶
Return True when
streamis an open interactive TTY.- Parameters:
stream (Any) –
- Return type:
bool
- imednet.cli.utils.terminal.supports_ansi_color(stream=None)[source]¶
Return True when ANSI SGR color sequences may be written to
stream.Defaults to
sys.stdout. Suppressed on non-TTY streams, underTERM=dumb, whenNO_COLORis set to a non-empty string, or onsys.stdoutwhen JSON output mode is active.- Parameters:
stream (Any) –
- Return type:
bool
- imednet.cli.utils.terminal.supports_fullscreen_ui(stdin=None, stdout=None)[source]¶
Return True when full-screen interactive UIs (such as curses grids) may run.
Requires interactive TTYs on both
stdinandstdout, a valid non-dumbTERMsetting backed by terminfo, and neither non-interactive mode nor JSON output mode.- Parameters:
stdin (Any) –
stdout (Any) –
- Return type:
bool
- imednet.cli.utils.terminal.supports_interactive_stdin(stdin=None)[source]¶
Return True when interactive line prompts may read from
stdin.- Parameters:
stdin (Any) –
- Return type:
bool
- imednet.cli.utils.terminal.supports_live_status(stream=None)[source]¶
Return True when VT100 cursor/line controls and live spinners may run on
stream.Defaults to
sys.stderr. Suppressed on non-TTY streams and under--format json,--no-interactive,IMEDNET_NON_INTERACTIVE=1, orTERM=dumb.- Parameters:
stream (Any) –
- Return type:
bool
imednet.cli.utils.write_helpers module¶
Shared CLI helpers for write commands (records create/update/import and subjects register).
- imednet.cli.utils.write_helpers.add_write_common_args(parser, *, default_chunk_size=100)[source]¶
Register standard write flags (schema, dry-run, wait, polling, output format).
- Parameters:
parser (ArgumentParser) –
default_chunk_size (int) –
- Return type:
None
- imednet.cli.utils.write_helpers.assemble_cli_write_records(args, *, schema=None, study_key=None, is_subject_registration=False, is_update=False)[source]¶
Unify CLI payload assembly for
records create/updateandsubjects register.- Parameters:
args (Namespace) –
schema (ValidationSchemaProtocol | None) –
study_key (str | None) –
is_subject_registration (bool) –
is_update (bool) –
- Return type:
list[dict[str, Any]]
- imednet.cli.utils.write_helpers.coerce_batch_summary(raw_result, *, study_key, total_records, dry_run=False, skipped_count=0, wait_for_completion=False)[source]¶
Coerce an SDK batch response (or mocked Job) into a
BatchSubmissionSummary.- Parameters:
raw_result (Any) –
study_key (str) –
total_records (int) –
dry_run (bool) –
skipped_count (int) –
wait_for_completion (bool) –
- Return type:
- imednet.cli.utils.write_helpers.execute_cli_write(operation, *, study_key, resource, output_format=None, dry_run=False, skipped_count=0, total_records=0)[source]¶
Orchestrate a CLI write command, emitting structured partial/validation failures before exit 1.
- Parameters:
operation (Callable[[], BatchSubmissionSummary]) –
study_key (str) –
resource (str) –
output_format (str | None) –
dry_run (bool) –
skipped_count (int | Callable[[], int]) –
total_records (int | Callable[[], int]) –
- Return type:
None
- imednet.cli.utils.write_helpers.exit_cli_validation_error(exc, *, resource='validation_error', study_key=None, output_format=None)[source]¶
Print a secret-redacted and PHI-masked CLI validation error, emit JSON if needed, and exit 1.
- Parameters:
exc (Exception) –
resource (str) –
study_key (str | None) –
output_format (str | None) –
- Return type:
NoReturn
- imednet.cli.utils.write_helpers.exit_cli_write_error(exc, *, resource='write_error', study_key=None, total_records=0, skipped_count=0, output_format=None)[source]¶
Print redacted/PHI-masked batch or job failure diagnostics, emit JSON if needed, and exit 1.
- Parameters:
exc (Exception) –
resource (str) –
study_key (str | None) –
total_records (int) –
skipped_count (int) –
output_format (str | None) –
- Return type:
NoReturn
- imednet.cli.utils.write_helpers.format_bounded_record_error_lines(record_errors, *, study_key=None, max_lines=10)[source]¶
Format PHI-sanitized per-record error items bounded to
max_linesplus overflow count.- Parameters:
record_errors (Sequence[Any]) –
study_key (str | None) –
max_lines (int) –
- Return type:
list[str]
- imednet.cli.utils.write_helpers.guard_stdin_dash_tty(file_arg)[source]¶
Exit 1 before SDK initialization if
'-'is requested on an interactive TTY stdin.- Parameters:
file_arg (str | None) –
- Return type:
None
- imednet.cli.utils.write_helpers.load_offline_schema(schema_source, *, study_key=None)[source]¶
Load an offline
DataDictionaryfrom JSON, ODM XML, REDCap CSV, ZIP, or CSV dir.- Parameters:
schema_source (str | Path) –
study_key (str | None) –
- Return type:
- imednet.cli.utils.write_helpers.load_records_from_path_or_stdin(file_arg, *, schema=None, study_key=None, default_form_key=None, default_form_id=None)[source]¶
Load record payloads from
'-'(piped stdin JSON or CSV),.json, or.csv.- Parameters:
file_arg (str) –
schema (ValidationSchemaProtocol | None) –
study_key (str | None) –
default_form_key (str | None) –
default_form_id (int | None) –
- Return type:
list[dict[str, Any]]
- imednet.cli.utils.write_helpers.make_job_progress_callback(status_ctrl=None)[source]¶
Create a job polling progress callback that updates
status_ctrlor live stderr.- Parameters:
status_ctrl (Any) –
- Return type:
JobProgressCallback | Callable[[JobStatusEvent], None]
- imednet.cli.utils.write_helpers.merge_inline_data_overrides(rec, data_pairs, *, schema=None, study_key=None, default_form_key=None, default_form_id=None)[source]¶
Merge repeatable
-d/--datakey-value overrides into a copied record payload dict.- Parameters:
rec (Mapping[str, Any]) –
data_pairs (Sequence[str] | None) –
schema (ValidationSchemaProtocol | None) –
study_key (str | None) –
default_form_key (str | None) –
default_form_id (int | None) –
- Return type:
dict[str, Any]
- imednet.cli.utils.write_helpers.parse_email_notify(raw_email_notify)[source]¶
Normalize and validate
--email-notifyvalue into bool or header-safe email string.- Parameters:
raw_email_notify (str | bool | None) –
- Return type:
bool | str | None
- imednet.cli.utils.write_helpers.parse_json_records_text(raw_text, *, source_label)[source]¶
Parse a JSON object or JSON array of record payload dicts.
- Parameters:
raw_text (str) –
source_label (str) –
- Return type:
list[dict[str, Any]]
- imednet.cli.utils.write_helpers.parse_key_value_pairs(pairs, *, schema=None, form_key=None, form_id=None, study_key=None)[source]¶
Parse repeatable
KEY=VALUEpairs from-d/--dataflags with optional schema types.- Parameters:
pairs (Sequence[str] | None) –
schema (ValidationSchemaProtocol | None) –
form_key (str | None) –
form_id (int | None) –
study_key (str | None) –
- Return type:
dict[str, Any]
- imednet.cli.utils.write_helpers.parse_stdin_records_text(raw_text, *, schema=None, study_key=None, default_form_key=None, default_form_id=None)[source]¶
Auto-detect and parse piped JSON or CSV record payloads from stdin text.
- Parameters:
raw_text (str) –
schema (ValidationSchemaProtocol | None) –
study_key (str | None) –
default_form_key (str | None) –
default_form_id (int | None) –
- Return type:
list[dict[str, Any]]
- imednet.cli.utils.write_helpers.render_write_summary(summary, *, resource, output_format=None)[source]¶
Render a
BatchSubmissionSummaryand exit 1 when validation or jobs fail.- Parameters:
summary (BatchSubmissionSummary) –
resource (str) –
output_format (str | None) –
- Return type:
None
- imednet.cli.utils.write_helpers.resolve_cli_schema(sdk, study_key, schema_source, *, dry_run=False)[source]¶
Resolve
--schemafrom disk or live study API variables.- Parameters:
sdk (ImednetSDK) –
study_key (str) –
schema_source (str | None) –
dry_run (bool) –
- Return type:
ValidationSchemaProtocol | None
- imednet.cli.utils.write_helpers.summary_from_job_failure(exc, *, study_key, total_records, skipped_count=0)[source]¶
Construct a
BatchSubmissionSummaryfrom a raisedJobFailedError.- Parameters:
exc (JobFailedError) –
study_key (str) –
total_records (int) –
skipped_count (int) –
- Return type:
- imednet.cli.utils.write_helpers.validate_write_numeric_flags(*, chunk_size, timeout, interval)[source]¶
Validate common numeric write flags before SDK initialization.
- Parameters:
chunk_size (int) –
timeout (float) –
interval (float) –
- Return type:
None
- imednet.cli.utils.write_helpers.write_progress_context(action_label, study_key, *, no_interactive=False, output_format=None, dry_run=False)[source]¶
Manage spinner and polling progress callbacks while honoring dry-run/non-interactive/JSON modes.
- Parameters:
action_label (str) –
study_key (str) –
no_interactive (bool) –
output_format (str | None) –
dry_run (bool) –
- Return type:
Iterator[JobProgressCallback | Callable[[JobStatusEvent], None] | None]