graflag.api

GraFlag Python API for GUI Integration.

Thin wrapper around GraFlag core that provides error-safe access and returns structured dataclass objects suitable for GUI/web consumption.

class graflag.api.GraFlagAPI(config_file: str = '.env', log_level: int = 20)[source]

Bases: object

High-level Python API for GraFlag operations.

All methods return structured data (dataclasses) and catch exceptions to avoid crashing the GUI. Use the core GraFlag class directly for CLI-style usage where exceptions should propagate.

Usage:

api = GraFlagAPI(config_file=”.env”)

cluster = api.get_cluster_info() methods = api.list_methods() experiments = api.list_experiments()

get_cluster_info() ClusterInfo[source]

Get cluster status information.

setup_cluster() Dict[str, Any][source]

Setup GraFlag cluster.

list_methods() List[MethodInfo][source]

List available methods.

get_method_details(method_name: str) MethodInfo | None[source]

Get details for a specific method.

list_datasets() List[DatasetInfo][source]

List available datasets.

list_experiments(limit: int = 50) List[ExperimentInfo][source]

List recent experiments.

get_experiment_details(experiment_name: str) ExperimentInfo | None[source]

Get details for a specific experiment.

run(method: str, dataset: str, tag: str = 'latest', build: bool = False, gpu: bool = True, method_params: Dict[str, Any] | None = None, on_progress: Callable[[RunProgress], None] | None = None) str[source]

Run an experiment. Returns experiment name.

get_experiment_results(experiment_name: str) ExperimentResults | None[source]

Get experiment results.

get_evaluation_results(experiment_name: str) EvaluationResults | None[source]

Get evaluation results.

evaluate_experiment(experiment_name: str) bool[source]

Run evaluation on an experiment.

list_running_services() List[Dict[str, str]][source]

List running Docker services.

stop_experiment(experiment_name: str) bool[source]

Stop a running experiment.

delete_experiment(experiment_name: str) bool[source]

Stop and delete an experiment.

get_experiment_logs(experiment_name: str, tail: int = 100) List[str][source]

Get recent logs for an experiment.

download_file(remote_path: str, local_path: str) bool[source]

Download a file from remote shared directory.

download_directory(remote_path: str, local_path: str) bool[source]

Download a directory from remote shared directory.