Modules API¶
Each module of pyclickplc lists its public names in __all__. This page lists them by module. A name that you can also import from pyclickplc links to the page that documents it. The other names are documented in their module's section.
pyclickplc.addresses¶
Address parsing, formatting, and the AddressRecord data model.
get_addr_keyparse_addr_keyis_xd_yd_hidden_slotxd_yd_display_to_mdbformat_address_displayiter_address_slotsparse_addressnormalize_addressAddressRecordmake_address_record
pyclickplc.addresses.get_addr_key ¶
Calculate AddrKey from memory type and MDB address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory_type
|
str
|
The memory type (X, Y, C, etc.) |
required |
address
|
int
|
The MDB address number |
required |
Returns:
| Type | Description |
|---|---|
int
|
The AddrKey value used as primary key in MDB |
Raises:
| Type | Description |
|---|---|
KeyError
|
If memory_type is not recognized |
pyclickplc.addresses.parse_addr_key ¶
Parse an AddrKey back to memory type and MDB address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr_key
|
int
|
The AddrKey value from MDB |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, int]
|
Tuple of (memory_type, mdb_address) |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the type index is not recognized |
pyclickplc.addresses.is_xd_yd_hidden_slot ¶
Check if an XD/YD MDB address is an odd address above 1. CLICK does not show these.
pyclickplc.addresses.xd_yd_display_to_mdb ¶
Convert XD/YD display address to MDB address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_addr
|
int
|
The display address (0-8) |
required |
upper_byte
|
bool
|
True for XD0u/YD0u (only valid for display_addr=0) |
False
|
Returns:
| Type | Description |
|---|---|
int
|
The MDB address |
pyclickplc.banks¶
PLC memory bank configuration and address validation.
DataTypeDATA_TYPE_DISPLAYDATA_TYPE_HINTSBankConfigBANKSMEMORY_TYPE_TO_DATA_TYPEBIT_ONLY_TYPESMEMORY_TYPE_BASESDEFAULT_RETENTIVEINTERLEAVED_PAIRSPAIRED_RETENTIVE_TYPESNON_EDITABLE_TYPESis_valid_address
pyclickplc.banks.DATA_TYPE_DISPLAY
module-attribute
¶
DATA_TYPE_DISPLAY: dict[int, str] = {
DataType.BIT: "BIT",
DataType.INT: "INT",
DataType.INT2: "INT2",
DataType.FLOAT: "FLOAT",
DataType.HEX: "HEX",
DataType.TXT: "TXT",
}
The display name of each DataType, such as "INT2".
pyclickplc.banks.DATA_TYPE_HINTS
module-attribute
¶
DATA_TYPE_HINTS: dict[int, str] = {
DataType.BIT: "0 or 1 (checkbox)",
DataType.INT: "Range: `-32768` to `32767`",
DataType.INT2: "Range: `-2147483648` to `2147483647`",
DataType.FLOAT: "Range: `-3.4028235E+38` to `3.4028235E+38`",
DataType.HEX: "Range: '0000' to 'FFFF'",
DataType.TXT: "Single cp1252 char: eg 'A' or 'é' (DataView new value: its byte 0..255)",
}
The hint text for an initial-value field, keyed by DataType.
pyclickplc.banks.MEMORY_TYPE_TO_DATA_TYPE
module-attribute
¶
The DataType of each memory type, taken from BANKS.
pyclickplc.banks.BIT_ONLY_TYPES
module-attribute
¶
BIT_ONLY_TYPES: frozenset[str] = frozenset(
name
for name, b in BANKS.items()
if b.data_type == DataType.BIT
)
The memory types whose addresses hold only bits: X, Y, C, T, CT and SC.
pyclickplc.banks.MEMORY_TYPE_BASES
module-attribute
¶
MEMORY_TYPE_BASES: dict[str, int] = {
"X": 0,
"Y": 16777216,
"C": 33554432,
"T": 50331648,
"CT": 67108864,
"SC": 83886080,
"DS": 100663296,
"DD": 117440512,
"DH": 134217728,
"DF": 150994944,
"XD": 167772160,
"YD": 184549376,
"TD": 201326592,
"CTD": 218103808,
"SD": 234881024,
"TXT": 251658240,
}
The AddrKey base of each memory type.
An AddrKey is the primary key of an address in CLICK's MDB database. get_addr_key adds the
MDB address to the base.
pyclickplc.banks.DEFAULT_RETENTIVE
module-attribute
¶
DEFAULT_RETENTIVE: dict[str, bool] = {
"X": False,
"Y": False,
"C": False,
"T": False,
"CT": True,
"SC": False,
"DS": True,
"DD": True,
"DH": True,
"DF": True,
"XD": False,
"YD": False,
"TD": False,
"CTD": True,
"SD": False,
"TXT": True,
}
Whether each memory type is retentive by default.
The values come from CLICK's documentation.
pyclickplc.banks.INTERLEAVED_PAIRS
module-attribute
¶
The partner of each timer and counter memory type.
T maps to TD and TD to T. CT maps to CTD and CTD to CT.
pyclickplc.banks.PAIRED_RETENTIVE_TYPES
module-attribute
¶
The memory types whose Retentive setting follows a paired type: TD follows T, CTD follows CT.
pyclickplc.banks.NON_EDITABLE_TYPES
module-attribute
¶
The memory types whose initial value and Retentive setting cannot be edited.
pyclickplc.banks.is_valid_address ¶
Check if an address is valid for the given bank.
Uses valid_ranges for sparse banks (X/Y), simple min/max for contiguous banks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bank_name
|
str
|
The bank name (e.g., "X", "DS") |
required |
address
|
int
|
The address number to validate |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the address is valid for the bank |
pyclickplc.blocks¶
Block tag parsing, matching, and range computation.
HasCommentBlockRangeBlockTagStructuredBlockNameparse_structured_block_namecompose_structured_block_nameparse_block_tagstrip_block_tagformat_block_tagis_block_name_availablefind_paired_tag_indexcompute_all_block_rangesvalidate_block_span
pyclickplc.blocks.HasComment ¶
Bases: Protocol
Protocol for objects that have a comment and optional memory_type attribute.
pyclickplc.blocks.BlockRange
dataclass
¶
A matched block range with start/end indices and metadata.
Represents a complete block from opening to closing tag (or self-closing).
pyclickplc.blocks.BlockTag
dataclass
¶
Result of parsing a block tag from a comment.
Block tags mark sections in the Address Editor:
-
pyclickplc.blocks.StructuredBlockName
dataclass
¶
The parts of a block name that follows a structured naming convention.
parse_block_tag() treats a block name as an opaque string. A caller that
wants to read one of these conventions calls parse_structured_block_name(),
which returns this class:
- Semantic blocks: Base:block / Base:block(start=n)
- UDT fields: Base.field:udt, or Base.field without the suffix
- Named arrays: Base:named_array(count,stride)
pyclickplc.blocks.parse_structured_block_name ¶
Parse a block name into its parts if it follows a structured naming convention.
This function never raises. If name does not match a convention exactly,
the result has kind="plain".
pyclickplc.blocks.compose_structured_block_name ¶
compose_structured_block_name(
base: str,
kind: Literal[
"plain", "udt", "named_array", "block"
] = "plain",
*,
field: str | None = None,
count: int | None = None,
stride: int | None = None,
start: int | None = None,
) -> str
Compose a structured block name string from its components.
Inverse of parse_structured_block_name().
pyclickplc.blocks.parse_block_tag ¶
Parse block tag from anywhere in a comment.
Block tags mark sections in the Address Editor:
-
The function searches for tags anywhere in the comment, not just at the start. Mathematical expressions like '< 5 >' are not parsed as tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comment
|
str
|
The comment string to parse |
required |
Returns:
| Type | Description |
|---|---|
BlockTag
|
BlockTag with name, tag_type, remaining_text, and bg_color |
pyclickplc.blocks.strip_block_tag ¶
Remove the first block tag from a comment and return the rest of the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comment
|
str
|
The comment string (e.g., " |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text before and after the tag (e.g., "Valve info"), or the |
str
|
comment unchanged if it has no tag |
pyclickplc.blocks.format_block_tag ¶
format_block_tag(
name: str,
tag_type: Literal["open", "close", "self-closing"],
bg_color: str | None = None,
) -> str
Format a block tag string from its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The block name (e.g., "Motor", "Alarms") |
required |
tag_type
|
Literal['open', 'close', 'self-closing']
|
"open", "close", or "self-closing" |
required |
bg_color
|
str | None
|
Optional background color (e.g., "#FFCDD2", "Red") |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted block tag string: |
str
|
|
str
|
|
str
|
|
pyclickplc.blocks.is_block_name_available ¶
is_block_name_available(
name: str,
rows: list[HasComment],
exclude_addr_keys: set[int] | None = None,
) -> bool
Check if a block name is available (not already in use).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The block name to check |
required |
rows
|
list[HasComment]
|
List of objects with .comment and .addr_key attributes |
required |
exclude_addr_keys
|
set[int] | None
|
Optional set of addr_keys to exclude from check (used when renaming a block - excludes the block being renamed) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the name is available, False if already in use |
pyclickplc.blocks.find_paired_tag_index ¶
find_paired_tag_index(
rows: Sequence[HasComment],
row_idx: int,
tag: BlockTag | None = None,
) -> int | None
Find the row index of the paired open/close block tag.
Uses nesting depth to correctly match tags when there are multiple blocks with the same name (nested or separate sections).
Only matches tags within the same memory_type (if available) to correctly handle interleaved views like T/TD where each type has its own tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Sequence[HasComment]
|
List of objects with .comment and optional .memory_type attributes |
required |
row_idx
|
int
|
Index of the row containing the tag |
required |
tag
|
BlockTag | None
|
Parsed BlockTag, or None to parse from rows[row_idx].comment |
None
|
Returns:
| Type | Description |
|---|---|
int | None
|
Row index of the paired tag, or None if not found |
pyclickplc.blocks.compute_all_block_ranges ¶
Compute all block ranges from a list of rows using stack-based matching.
Correctly handles nested blocks and multiple blocks with the same name. Only matches open/close tags within the same memory_type to handle interleaved views like T/TD correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
Sequence[HasComment]
|
List of objects with .comment and optional .memory_type attributes |
required |
Returns:
| Type | Description |
|---|---|
list[BlockRange]
|
List of BlockRange objects, sorted by start_idx |
pyclickplc.blocks.validate_block_span ¶
Validate that a block span doesn't cross memory type boundaries.
Blocks should only contain addresses of the same memory type, with the exception of paired types (T+TD, CT+CTD) which are interleaved and can share blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list
|
List of objects with .memory_type attribute |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Tuple of (is_valid, error_message). |
str | None
|
|
tuple[bool, str | None]
|
|
pyclickplc.client¶
Async Modbus TCP client driver for AutomationDirect CLICK PLCs.
pyclickplc.dataview¶
DataView model and CDV file I/O for CLICK PLC DataView files.
MAX_DATAVIEW_ROWSget_data_type_for_addressDataViewRecordmake_dataview_recordvalidate_new_valueDataViewFileread_cdvwrite_cdvcheck_cdv_fileverify_cdv
pyclickplc.dataview.MAX_DATAVIEW_ROWS
module-attribute
¶
The most rows that a DataView holds.
pyclickplc.modbus¶
Modbus protocol mapping layer for CLICK PLCs.
pyclickplc.modbus.MODBUS_MAPPINGS
module-attribute
¶
MODBUS_MAPPINGS: dict[str, ModbusMapping] = {
"X": ModbusMapping(
"X", 0, frozenset({2}), is_coil=True
),
"Y": ModbusMapping(
"Y", 8192, frozenset({1, 5, 15}), is_coil=True
),
"C": ModbusMapping(
"C", 16384, frozenset({1, 5, 15}), is_coil=True
),
"T": ModbusMapping(
"T", 45056, frozenset({1, 2, 5, 15}), is_coil=True
),
"CT": ModbusMapping(
"CT", 49152, frozenset({1, 2, 5, 15}), is_coil=True
),
"SC": ModbusMapping(
"SC",
61440,
frozenset({2}),
is_coil=True,
writable=_MODBUS_WRITABLE_SC,
),
"DS": ModbusMapping(
"DS",
0,
frozenset({3, 6, 16}),
is_coil=False,
width=1,
signed=True,
),
"DD": ModbusMapping(
"DD",
16384,
frozenset({3, 6, 16}),
is_coil=False,
width=2,
signed=True,
),
"DH": ModbusMapping(
"DH",
24576,
frozenset({3, 6, 16}),
is_coil=False,
width=1,
signed=False,
),
"DF": ModbusMapping(
"DF",
28672,
frozenset({3, 6, 16}),
is_coil=False,
width=2,
signed=False,
),
"TXT": ModbusMapping(
"TXT",
36864,
frozenset({3, 6, 16}),
is_coil=False,
width=1,
signed=False,
),
"TD": ModbusMapping(
"TD",
45056,
frozenset({3, 6, 16}),
is_coil=False,
width=1,
signed=True,
),
"CTD": ModbusMapping(
"CTD",
49152,
frozenset({3, 6, 16}),
is_coil=False,
width=2,
signed=True,
),
"XD": ModbusMapping(
"XD",
57344,
frozenset({4}),
is_coil=False,
width=1,
signed=False,
),
"YD": ModbusMapping(
"YD",
57856,
frozenset({3, 6, 16}),
is_coil=False,
width=1,
signed=False,
),
"SD": ModbusMapping(
"SD",
61440,
frozenset({4}),
is_coil=False,
width=1,
signed=False,
writable=_MODBUS_WRITABLE_SD,
),
}
The ModbusMapping of each memory bank, keyed by bank name.
pyclickplc.modbus_service¶
Synchronous Modbus service for UI callers.
pyclickplc.nicknames¶
CSV read/write for CLICK PLC address nicknames.
CSV_ENCODINGfirst_non_cp1252_charAddressRecordMapREQUIRED_COLUMNSread_csvformat_csvwrite_csvread_mdb_csv
pyclickplc.nicknames.CSV_ENCODING
module-attribute
¶
The name of the codec that read_csv and write_csv use for the nickname CSV.
pyclickplc.nicknames.REQUIRED_COLUMNS
module-attribute
¶
The columns that read_csv requires by default.
A caller can pass other columns in required.
pyclickplc.plcdata¶
Read / write Click PLC 'Read Data from PLC' CSV dump files.
pyclickplc.project¶
Read installed modules, channel parameters and the PLC name from CLICK's Project.ini.
ModuleModulesChannelParametersModuleIOUnknownModuleread_modulesread_channel_parametersread_io_layoutread_plc_namewrite_plc_name
pyclickplc.server¶
Modbus TCP server simulating an AutomationDirect CLICK PLC.
pyclickplc.server.PlcValue
module-attribute
¶
A value that a DataProvider reads or writes.
pyclickplc.server.DataProvider ¶
Bases: Protocol
Backend protocol for PLC value storage.
pyclickplc.server_tui¶
Minimal interactive terminal UI for ClickServer.
pyclickplc.system¶
CLICK's current nicknames for its SC and SD system addresses.
AUTOMATIONDIRECT_SYSTEM_CONTROL_RELAY_SOURCEAUTOMATIONDIRECT_SYSTEM_DATA_REGISTER_SOURCEAUTOMATIONDIRECT_SYSTEM_NICKNAME_REVIEWED_ONAUTOMATIONDIRECT_SYSTEM_NICKNAMESSystemNicknameGuidancecanonical_system_nicknamecanonicalize_system_nicknameis_canonical_system_nickname
pyclickplc.validation¶
Validation functions for PLC address data.
NICKNAME_MAX_LENGTHCOMMENT_MAX_LENGTHCLICK_NAME_MAX_LENGTHCLICK_NAME_PATTERNSYSTEM_NICKNAME_TYPESINT_MININT_MAXINT2_MININT2_MAXFLOAT_MINFLOAT_MAXvalidate_nicknamevalidate_commentvalidate_click_namevalidate_initial_valueinitial_value_warningassert_runtime_value
pyclickplc.validation.NICKNAME_MAX_LENGTH
module-attribute
¶
The most characters that a nickname may have.
pyclickplc.validation.COMMENT_MAX_LENGTH
module-attribute
¶
The most characters that an address comment may have.
pyclickplc.validation.CLICK_NAME_MAX_LENGTH
module-attribute
¶
The most characters that a PLC or DataView name may have.
pyclickplc.validation.CLICK_NAME_PATTERN
module-attribute
¶
The pattern that a whole PLC or DataView name must match.
A name may contain the ASCII letters A to Z and a to z, digits, spaces, underscores and hyphens.
pyclickplc.validation.INT_MIN
module-attribute
¶
The lowest value that an INT address (DS, SD or TD) holds.
pyclickplc.validation.INT_MAX
module-attribute
¶
The highest value that an INT address (DS, SD or TD) holds.
pyclickplc.validation.INT2_MIN
module-attribute
¶
The lowest value that an INT2 address (DD or CTD) holds.
pyclickplc.validation.INT2_MAX
module-attribute
¶
The highest value that an INT2 address (DD or CTD) holds.
pyclickplc.validation.FLOAT_MIN
module-attribute
¶
The lowest value that the validators accept for a FLOAT address (DF).
It is the negative of float32's largest finite value, rounded to eight digits.
pyclickplc.validation.FLOAT_MAX
module-attribute
¶
The highest value that the validators accept for a FLOAT address (DF).
It is float32's largest finite value, rounded to eight digits.
pyclickplc.validation.assert_runtime_value ¶
assert_runtime_value(
data_type: DataType,
value: object,
*,
bank: str,
index: int,
allow_non_finite: bool = True,
) -> None
Raise ValueError if value cannot be written to an address of data_type.
bank and index name the address in the message. The message also says which values
the address accepts. A DF accepts +inf, -inf and NaN unless allow_non_finite is False.