module documentation

Utilities for deriving Python-friendly names from protobuf identifiers.

Exception NameError Raised when a name cannot be converted into a valid Python identifier.
Function enum Return a Python enum name from a protobuf enum name.
Function enum_value Return a Python constant name for an enum value.
Function field Return a Python attribute name for a message field.
Function first_non_underscore Return the first non-underscore character or an empty string.
Function is_reserved_name Return True if s is a Python keyword or soft keyword.
Function message Return a Python message name from a protobuf message name.
Function method Return a Python method name for a service method.
Function one_of Return a Python attribute name for a oneof declaration.
Function pascal_to_snake_case Convert a PascalCase string to snake_case.
Function service Return a Python service class name from a protobuf service name.
Variable logger Undocumented
Variable pep8_attr_re Undocumented
Variable pep8_class_re Undocumented
Variable pep8_const_re Undocumented
Variable pep8_method_re Undocumented
Function _class_name Resolve a Python class name from a protobuf full name.
Function _modify_name Adjust a proposed name to avoid reserved words and conflicts.
def enum(full_enum_name: str, annotated_name: str = '', full_proto_name: str = '') -> str: (source)

Return a Python enum name from a protobuf enum name.

Parameters
full_enum_name:strFully qualified proto enum name.
annotated_name:strOptional explicit name from annotations.
full_proto_name:strFully qualified proto name for warnings.
Returns
strValid Python enum class name.
Raises
NameErrorIf the annotated name is invalid.
def enum_value(value_name: str, enum_name: str, annotated_name: str = '', full_proto_name: str = '') -> str: (source)

Return a Python constant name for an enum value.

Parameters
value_name:strEnum value name in proto.
enum_name:strContaining enum name.
annotated_name:strOptional explicit name from annotations.
full_proto_name:strFully qualified proto name for warnings.
Returns
strValid Python constant name.
Raises
NameErrorIf the annotated name is invalid.
def field(field_name: str, message_name: str, annotated_name: str = '', full_proto_name: str = '') -> str: (source)

Return a Python attribute name for a message field.

Parameters
field_name:strField name in proto.
message_name:strContaining message name.
annotated_name:strOptional explicit name from annotations.
full_proto_name:strFully qualified proto name for warnings.
Returns
strValid Python attribute name.
Raises
NameErrorIf the annotated name is invalid.
def first_non_underscore(s: str) -> str: (source)

Return the first non-underscore character or an empty string.

Parameters
s:strInput string.
Returns
strFirst non-underscore character or "".
def is_reserved_name(s: str) -> bool: (source)

Return True if s is a Python keyword or soft keyword.

Parameters
s:strName to test.
Returns
boolTrue if reserved.
def message(full_enum_name: str, annotated_name: str = '') -> str: (source)

Return a Python message name from a protobuf message name.

Parameters
full_enum_name:strFully qualified proto message name.
annotated_name:strOptional explicit name from annotations.
Returns
strValid Python message class name.
Raises
NameErrorIf the annotated name is invalid.
def method(method_name: str, service_name: str, annotated_name: str = '', full_proto_name: str = '') -> str: (source)

Return a Python method name for a service method.

Parameters
method_name:strProto method name.
service_name:strContaining service name.
annotated_name:strOptional explicit name from annotations.
full_proto_name:strFully qualified proto name for warnings.
Returns
strValid Python method name.
Raises
NameErrorIf the annotated name is invalid.
def one_of(field_name: str, message_name: str, annotated_name: str = '', full_proto_name: str = '') -> str: (source)

Return a Python attribute name for a oneof declaration.

Parameters
field_name:strOneof field name.
message_name:strContaining message name.
annotated_name:strOptional explicit name from annotations.
full_proto_name:strFully qualified proto name for warnings.
Returns
strValid Python attribute name.
Raises
NameErrorIf the annotated name is invalid.
def pascal_to_snake_case(name: str) -> str: (source)

Convert a PascalCase string to snake_case.

This conversion preserves leading underscores and splits abbreviations.

Parameters
name:strPascalCase name.
Returns
strsnake_case representation.
def service(full_service_name: str, annotated_name: str = '') -> str: (source)

Return a Python service class name from a protobuf service name.

Parameters
full_service_name:strFully qualified proto service name.
annotated_name:strOptional explicit name from annotations.
Returns
strValid Python service class name.
Raises
NameErrorIf the annotated name is invalid.

Undocumented

pep8_attr_re = (source)

Undocumented

pep8_class_re = (source)

Undocumented

pep8_const_re = (source)

Undocumented

pep8_method_re = (source)

Undocumented

def _class_name(full_name: str, annotated_name: str = '') -> str: (source)

Resolve a Python class name from a protobuf full name.

Parameters
full_name:strFully qualified proto name.
annotated_name:strOptional explicit name from annotations.
Returns
strValid Python class name.
Raises
NameErrorIf the annotated name is invalid.
def _modify_name(suggested_name: str, container_name: str, *, lower: bool = True, full_proto_name: str = '') -> str: (source)

Adjust a proposed name to avoid reserved words and conflicts.

Parameters
suggested_name:strInitial candidate name.
container_name:strEnclosing scope name used for conflict prefixes.
lower:boolWhether to lower the prefix letter.
full_proto_name:strFully qualified proto name for warnings.
Returns
strAdjusted name.