Core API Reference¶
The core API provides the main entry point for using the Bluetooth SIG Standards Library.
Pure Bluetooth SIG standards translator for characteristic and service interpretation.
This class provides the primary API surface for Bluetooth SIG standards translation, covering characteristic parsing, service discovery, UUID resolution, and registry management.
Key features: - Parse raw BLE characteristic data using Bluetooth SIG specifications - Resolve UUIDs to CharacteristicInfo and ServiceInfo - Create BaseGattService instances from service UUIDs - Access comprehensive registry of supported characteristics and services
Note: This class intentionally has >20 public methods as it serves as the primary API surface for Bluetooth SIG standards translation. The methods are organized by functionality and reducing them would harm API clarity.
Initialize the SIG translator.
Source code in src/bluetooth_sig/core/translator.py
discovered_services
property
¶
Get list of discovered service instances.
Returns:
| Type | Description |
|---|---|
list[BaseGattService]
|
List of discovered service instances |
__str__
¶
clear_services
¶
get_characteristic_info_by_name
¶
get_characteristic_info_by_name(name: CharacteristicName) -> CharacteristicInfo | None
Get characteristic info by enum name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
CharacteristicName
|
CharacteristicName enum |
required |
Returns:
| Type | Description |
|---|---|
CharacteristicInfo | None
|
CharacteristicInfo if found, None otherwise |
Source code in src/bluetooth_sig/core/translator.py
get_characteristic_info_by_uuid
¶
get_characteristic_info_by_uuid(uuid: str) -> CharacteristicInfo | None
Get information about a characteristic by UUID.
Retrieve metadata for a Bluetooth characteristic using its UUID. This includes the characteristic's name, description, value type, unit, and properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
The characteristic UUID (16-bit short form or full 128-bit) |
required |
Returns:
| Type | Description |
|---|---|
CharacteristicInfo | None
|
CharacteristicInfo with metadata or None if not found |
Example
Get battery level characteristic info:
Source code in src/bluetooth_sig/core/translator.py
get_characteristic_uuid_by_name
¶
Get the UUID for a characteristic name enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
CharacteristicName
|
CharacteristicName enum |
required |
Returns:
| Type | Description |
|---|---|
BluetoothUUID | None
|
Characteristic UUID or None if not found |
Source code in src/bluetooth_sig/core/translator.py
get_characteristics_info_by_uuids
¶
get_characteristics_info_by_uuids(uuids: list[str]) -> dict[str, CharacteristicInfo | None]
Get information about multiple characteristics by UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuids
|
list[str]
|
List of characteristic UUIDs |
required |
Returns:
| Type | Description |
|---|---|
dict[str, CharacteristicInfo | None]
|
Dictionary mapping UUIDs to CharacteristicInfo |
dict[str, CharacteristicInfo | None]
|
(or None if not found) |
Source code in src/bluetooth_sig/core/translator.py
get_service_by_uuid
¶
Get a service instance by UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
The service UUID |
required |
Returns:
| Type | Description |
|---|---|
BaseGattService | None
|
Service instance if found, None otherwise |
Source code in src/bluetooth_sig/core/translator.py
get_service_characteristics
¶
Get the characteristic UUIDs associated with a service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_uuid
|
str
|
The service UUID |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of characteristic UUIDs for this service |
Source code in src/bluetooth_sig/core/translator.py
get_service_info_by_name
¶
get_service_info_by_name(name: str) -> ServiceInfo | None
Get service info by name instead of UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Service name |
required |
Returns:
| Type | Description |
|---|---|
ServiceInfo | None
|
ServiceInfo if found, None otherwise |
Source code in src/bluetooth_sig/core/translator.py
get_service_info_by_uuid
¶
get_service_info_by_uuid(uuid: str) -> ServiceInfo | None
Get information about a service by UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
The service UUID |
required |
Returns:
| Type | Description |
|---|---|
ServiceInfo | None
|
ServiceInfo with metadata or None if not found |
Source code in src/bluetooth_sig/core/translator.py
get_service_uuid_by_name
¶
Get the UUID for a service name or enum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | ServiceName
|
Service name or enum |
required |
Returns:
| Type | Description |
|---|---|
BluetoothUUID | None
|
Service UUID or None if not found |
Source code in src/bluetooth_sig/core/translator.py
get_sig_info_by_name
¶
Get Bluetooth SIG information for a characteristic or service by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Characteristic or service name |
required |
Returns:
| Type | Description |
|---|---|
SIGInfo | None
|
CharacteristicInfo or ServiceInfo if found, None otherwise |
Source code in src/bluetooth_sig/core/translator.py
get_sig_info_by_uuid
¶
Get Bluetooth SIG information for a UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
UUID string (with or without dashes) |
required |
Returns:
| Type | Description |
|---|---|
SIGInfo | None
|
CharacteristicInfo or ServiceInfo if found, None otherwise |
Source code in src/bluetooth_sig/core/translator.py
list_supported_characteristics
¶
List all supported characteristics with their names and UUIDs.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping characteristic names to UUIDs |
Source code in src/bluetooth_sig/core/translator.py
list_supported_services
¶
List all supported services with their names and UUIDs.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping service names to UUIDs |
Source code in src/bluetooth_sig/core/translator.py
parse_characteristic
¶
parse_characteristic(uuid: str, raw_data: bytes, ctx: CharacteristicContext | None = None, descriptor_data: dict[str, bytes] | None = None) -> CharacteristicData
Parse a characteristic's raw data using Bluetooth SIG standards.
This method takes raw BLE characteristic data and converts it to structured, type-safe Python objects using official Bluetooth SIG specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
The characteristic UUID (with or without dashes) |
required |
raw_data
|
bytes
|
Raw bytes from the characteristic |
required |
ctx
|
CharacteristicContext | None
|
Optional CharacteristicContext providing device-level info and previously-parsed characteristics to the parser. |
None
|
properties
|
Optional set of characteristic properties (unused, kept for protocol compatibility) |
required | |
descriptor_data
|
dict[str, bytes] | None
|
Optional dictionary mapping descriptor UUIDs to their raw data |
None
|
Returns:
| Type | Description |
|---|---|
CharacteristicData
|
CharacteristicData with parsed value and metadata |
Example
Parse battery level data:
Source code in src/bluetooth_sig/core/translator.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
parse_characteristics
¶
parse_characteristics(char_data: dict[str, bytes], descriptor_data: dict[str, dict[str, bytes]] | None = None, ctx: CharacteristicContext | None = None) -> dict[str, CharacteristicData]
Parse multiple characteristics at once with dependency-aware ordering.
This method automatically handles multi-characteristic dependencies by parsing
independent characteristics first, then parsing characteristics that depend on them.
The parsing order is determined by the required_dependencies and optional_dependencies
attributes declared on characteristic classes.
Required dependencies MUST be present and successfully parsed; missing required dependencies result in parse failure with MissingDependencyError. Optional dependencies enrich parsing when available but are not mandatory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
char_data
|
dict[str, bytes]
|
Dictionary mapping UUIDs to raw data bytes |
required |
descriptor_data
|
dict[str, dict[str, bytes]] | None
|
Optional nested dictionary mapping characteristic UUIDs to dictionaries of descriptor UUIDs to raw descriptor data |
None
|
ctx
|
CharacteristicContext | None
|
Optional CharacteristicContext used as the starting device-level context for each parsed characteristic. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, CharacteristicData]
|
Dictionary mapping UUIDs to CharacteristicData results |
dict[str, CharacteristicData]
|
with parsed descriptors included when descriptor_data is provided |
Raises:
| Type | Description |
|---|---|
ValueError
|
If circular dependencies are detected |
Example
Parse multiple environmental characteristics:
Source code in src/bluetooth_sig/core/translator.py
process_services
¶
Process discovered services and their characteristics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
services
|
dict[str, dict[str, CharacteristicDataDict]]
|
Dictionary of service UUIDs to their characteristics |
required |
Source code in src/bluetooth_sig/core/translator.py
register_custom_characteristic_class
¶
register_custom_characteristic_class(uuid_or_name: str, cls: type[BaseCharacteristic], metadata: CharacteristicRegistration | None = None, override: bool = False) -> None
Register a custom characteristic class at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid_or_name
|
str
|
The characteristic UUID or name |
required |
cls
|
type[BaseCharacteristic]
|
The characteristic class to register |
required |
metadata
|
CharacteristicRegistration | None
|
Optional metadata dataclass with name, unit, value_type, summary |
None
|
override
|
bool
|
Whether to override existing registrations |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If cls does not inherit from BaseCharacteristic |
ValueError
|
If UUID conflicts with existing registration and override=False |
Source code in src/bluetooth_sig/core/translator.py
register_custom_service_class
¶
register_custom_service_class(uuid_or_name: str, cls: type[BaseGattService], metadata: ServiceRegistration | None = None, override: bool = False) -> None
Register a custom service class at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid_or_name
|
str
|
The service UUID or name |
required |
cls
|
type[BaseGattService]
|
The service class to register |
required |
metadata
|
ServiceRegistration | None
|
Optional metadata dataclass with name, summary |
None
|
override
|
bool
|
Whether to override existing registrations |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If cls does not inherit from BaseGattService |
ValueError
|
If UUID conflicts with existing registration and override=False |
Source code in src/bluetooth_sig/core/translator.py
validate_characteristic_data
¶
validate_characteristic_data(uuid: str, data: bytes) -> ValidationResult
Validate characteristic data format against SIG specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
The characteristic UUID |
required |
data
|
bytes
|
Raw data bytes to validate |
required |
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation details |
Source code in src/bluetooth_sig/core/translator.py
Quick Examples¶
Parse Characteristic Data¶
from bluetooth_sig import BluetoothSIGTranslator
translator = BluetoothSIGTranslator()
# Parse battery level - returns CharacteristicData
result = translator.parse_characteristic("2A19", bytearray([85]))
print(f"Battery: {result.value}%") # Battery: 85%
print(f"Unit: {result.info.unit}") # Unit: %
The parse_characteristic method returns a CharacteristicData object.
UUID Resolution¶
# Resolve UUID to get information
service_info = translator.get_sig_info_by_uuid("180F")
print(service_info.name) # "Battery Service"
# Resolve characteristic
char_info = translator.get_sig_info_by_uuid("2A19")
print(char_info.name) # "Battery Level"
See get_sig_info_by_uuid for full details.
battery_level = translator.get_sig_info("Battery Level")
Name Resolution¶
# Resolve name to UUID
battery_service = translator.get_sig_info_by_name("Battery Service")
print(battery_service.uuid) # "180F"
battery_level = translator.get_sig_info_by_name("Battery Level")
print(battery_level.uuid) # "2A19"
Error Handling¶
from bluetooth_sig.gatt.exceptions import (
UUIDResolutionError,
InsufficientDataError,
ValueRangeError,
)
try:
result = translator.parse_characteristic("2A19", data)
except UUIDResolutionError:
print("Unknown UUID")
except InsufficientDataError:
print("Data too short")
except ValueRangeError:
print("Value out of range")
See Also¶
- GATT Layer - Lower-level GATT APIs
- Registry System - UUID registry details
- Usage Guide - Practical examples
Type Definitions¶
These types are returned by the core API methods:
bluetooth_sig.types.CharacteristicData
¶
Bases: Struct
Parsed characteristic data with validation results.
Provides structured error reporting with field-level diagnostics and parse traces to help identify exactly where and why parsing failed.
NOTE: This struct intentionally has more attributes than the standard limit to provide complete diagnostic information. The additional fields (field_errors, parse_trace) are essential for actionable error reporting and debugging.
bluetooth_sig.types.CharacteristicInfo
¶
Bases: SIGInfo
Information about a Bluetooth characteristic.
properties
class-attribute
instance-attribute
¶
bluetooth_sig.types.ServiceInfo
¶
Bases: SIGInfo
Information about a Bluetooth service.
characteristics
class-attribute
instance-attribute
¶
characteristics: list[CharacteristicInfo] = field(default_factory=list)
bluetooth_sig.types.ValidationResult
¶
Bases: SIGInfo
Result of data validation.