Schema Introspection
xbbg.schema
Section titled “xbbg.schema”Bloomberg schema introspection and stub generation.
This module provides access to cached Bloomberg service schemas and can generate Python type stubs for IDE autocomplete support.
Example:
import xbbg from xbbg.schema import get_schema, list_operations
Get schema for a service
Section titled “Get schema for a service”schema = await get_schema(“//blp/refdata”)
List available operations
Section titled “List available operations”ops = await list_operations(“//blp/refdata”) print(ops) # [‘ReferenceDataRequest’, ‘HistoricalDataRequest’, …]
Get enum values for an element
Section titled “Get enum values for an element”values = await get_enum_values(“//blp/refdata”, “ReferenceDataRequest”, “periodicitySelection”)
ElementInfo Objects
Section titled “ElementInfo Objects”@dataclassclass ElementInfo()Schema element information.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, d: dict[str, Any]) -> ElementInfoCreate from dictionary (parsed JSON).
OperationSchema Objects
Section titled “OperationSchema Objects”@dataclassclass OperationSchema()Schema for a service operation.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, d: dict[str, Any]) -> OperationSchemaCreate from dictionary (parsed JSON).
ServiceSchema Objects
Section titled “ServiceSchema Objects”@dataclassclass ServiceSchema()Schema for a Bloomberg service.
from_dict
Section titled “from_dict”@classmethoddef from_dict(cls, d: dict[str, Any]) -> ServiceSchemaCreate from dictionary (parsed JSON).
from_json
Section titled “from_json”@classmethoddef from_json(cls, json_str: str) -> ServiceSchemaCreate from JSON string.
get_operation
Section titled “get_operation”def get_operation(name: str) -> OperationSchema | NoneGet an operation by name.
aget_schema
Section titled “aget_schema”async def aget_schema(service: str) -> ServiceSchemaGet schema for a service (async).
Loads from cache if available, otherwise introspects the service.
Arguments:
service- Service URI (e.g., “//blp/refdata”)
Returns:
ServiceSchema object with operations and element definitions.
aget_operation
Section titled “aget_operation”async def aget_operation(service: str, operation: str) -> OperationSchemaGet schema for a specific operation (async).
Arguments:
service- Service URI (e.g., “//blp/refdata”)operation- Operation name (e.g., “ReferenceDataRequest”)
Returns:
OperationSchema object with request/response definitions.
alist_operations
Section titled “alist_operations”async def alist_operations(service: str) -> list[str]List all operations for a service (async).
Arguments:
service- Service URI (e.g., “//blp/refdata”)
Returns:
List of operation names.
aget_enum_values
Section titled “aget_enum_values”async def aget_enum_values(service: str, operation: str, element: str) -> list[str] | NoneGet valid enum values for an element (async).
Arguments:
service- Service URIoperation- Operation nameelement- Element name
Returns:
List of valid enum values, or None if not an enum.
alist_valid_elements
Section titled “alist_valid_elements”async def alist_valid_elements(service: str, operation: str) -> list[str] | NoneList all valid element names for an operation (async).
Arguments:
service- Service URIoperation- Operation name
Returns:
List of valid element names.
get_schema
Section titled “get_schema”def get_schema(service: str) -> ServiceSchemaGet schema for a service (sync wrapper).
get_operation
Section titled “get_operation”def get_operation(service: str, operation: str) -> OperationSchemaGet schema for a specific operation (sync wrapper).
list_operations
Section titled “list_operations”def list_operations(service: str) -> list[str]List all operations for a service (sync wrapper).
get_enum_values
Section titled “get_enum_values”def get_enum_values(service: str, operation: str, element: str) -> list[str] | NoneGet valid enum values for an element (sync wrapper).
list_valid_elements
Section titled “list_valid_elements”def list_valid_elements(service: str, operation: str) -> list[str] | NoneList all valid element names for an operation (sync wrapper).
list_cached_schemas
Section titled “list_cached_schemas”def list_cached_schemas() -> list[str]List all cached service URIs.
invalidate_schema
Section titled “invalidate_schema”def invalidate_schema(service: str) -> NoneInvalidate a cached schema.
clear_schema_cache
Section titled “clear_schema_cache”def clear_schema_cache() -> NoneClear all cached schemas.
configure_ide_stubs
Section titled “configure_ide_stubs”def configure_ide_stubs(stubs_dir: Path | str | None = None, ide: str | None = None) -> strConfigure IDE to recognize xbbg type stubs.
Only modifies existing config files - does not create new ones.
Arguments:
stubs_dir- Stubs directory (default: ~/.xbbg/stubs/)ide- IDE to configure: “vscode”, “pyright”, “pyproject”, “ty”, or None for auto-detect
Returns:
Message describing what was configured or manual instructions.
generate_stubs
Section titled “generate_stubs”def generate_stubs(service: str, output_dir: Path | str | None = None) -> strGenerate Python type stubs for a service.
Creates .pyi files with TypedDict definitions for request/response types. Stubs are generated locally for IDE support - never committed to repos.
Arguments:
service- Service URI (e.g., “//blp/refdata”)output_dir- Output directory (default: ~/.xbbg/stubs/)
Returns:
Path to the generated stub file.