function get_relationship_types
Retrieves a dictionary of relationship type constants from the RelTypes class, filtering out private attributes that start with underscore.
/tf/active/vicechatdev/CDocs/db/schema_manager.py
510 - 513
simple
Purpose
This function provides a programmatic way to access all public relationship type constants defined in the RelTypes class. It's useful for dynamically discovering available relationship types in a graph database schema, validating relationship types, or generating documentation. The function introspects the RelTypes class and returns only the public constants, making it ideal for runtime type checking or UI generation where relationship types need to be displayed or selected.
Source Code
def get_relationship_types() -> Dict[str, str]:
"""Get dictionary of relationship type constants."""
return {key: value for key, value in vars(RelTypes).items()
if not key.startswith('_')}
Return Value
Type: Dict[str, str]
Returns a dictionary where keys are the attribute names from the RelTypes class (as strings) and values are the corresponding relationship type constant values (as strings). Only includes public attributes (those not starting with underscore). For example, if RelTypes has attributes like 'PARENT_OF' and 'CHILD_OF', the returned dictionary would be {'PARENT_OF': 'PARENT_OF', 'CHILD_OF': 'CHILD_OF'} or similar depending on the actual values stored in RelTypes.
Dependencies
typing
Required Imports
from typing import Dict
Usage Example
# Assuming RelTypes class is defined with relationship constants
# class RelTypes:
# PARENT_OF = 'PARENT_OF'
# CHILD_OF = 'CHILD_OF'
# RELATED_TO = 'RELATED_TO'
rel_types = get_relationship_types()
print(rel_types)
# Output: {'PARENT_OF': 'PARENT_OF', 'CHILD_OF': 'CHILD_OF', 'RELATED_TO': 'RELATED_TO'}
# Use case: Validate a relationship type
if 'PARENT_OF' in rel_types:
print(f"Valid relationship type: {rel_types['PARENT_OF']}")
# Use case: Get all available relationship types for a dropdown
available_types = list(rel_types.keys())
Best Practices
- Ensure the RelTypes class is properly defined before calling this function, otherwise it will raise a NameError
- The function assumes RelTypes attributes are string constants; if they are other types, the return type annotation may be misleading
- This function creates a new dictionary on each call, so consider caching the result if called frequently
- The filtering logic (not key.startswith('_')) excludes Python magic methods and private attributes, which is the intended behavior
- If RelTypes is modified at runtime, subsequent calls to this function will reflect those changes
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class RelTypes 76.9% similar
-
function get_node_labels 51.7% similar
-
function create_references_sampletypes_relationship 50.3% similar
-
function create_references_medicationtypes_relationship 49.8% similar
-
function get_database_statistics 49.2% similar