Core Functions
kandc.init()
Initialize a new experiment run with configuration and tracking.
project(str, optional): Project name for organizationname(str, optional): Run name (auto-generated if not provided)config(dict, optional): Hyperparameters and configuration to tracktags(list, optional): Tags for filtering and organizationnotes(str, optional): Optional description or notesdir(str/Path, optional): Directory to save run datamode(str, optional): Run mode - “online”, “offline”, or “disabled”reinit(bool): Whether to reinitialize if already initializedopen_browser(bool): Whether to open dashboard in browser (online mode)capture_code(bool): Whether to capture code snapshotcode_exclude_patterns(list, optional): Patterns to exclude from code capture
Run object representing the initialized experiment
Examples:
kandc.log()
Log metrics and data during experiment execution.
data(dict): Dictionary of metrics to logx(float, optional): Custom x-axis value (step, epoch, time, etc.)
kandc.finish()
Finish the current run and ensure all data is saved and synced.
kandc.get_current_run()
Get the currently active run object.
Run object or None if not initialized
Example:
kandc.is_initialized()
Check if kandc is currently initialized.
True if initialized, False otherwise
Example:
PyTorch Profiling
kandc.ProfilerWrapper
Wrap any object with PyTorch profiler integration.
obj: The object to wrap and profilename(str, optional): Name for the wrapped object in logsactivities(list, optional): Activities to profile [‘cpu’, ‘cuda’]. Defaults to both.record_shapes(bool): Whether to record tensor shapesprofile_memory(bool): Whether to profile memory usagewith_stack(bool): Whether to record call stacks
kandc.ProfilerDecorator
Decorator for automatic PyTorch profiling of classes or functions.
kandc.profile()
Convenience function to wrap an object with PyTorch profiling.
kandc.profiler()
Convenience function to create a PyTorch profiler decorator.
Model Profiling
kandc.capture_model_class()
Decorator to automatically profile PyTorch model classes.
model_name(str, optional): Name for the model traces (defaults to class name)record_shapes(bool): Whether to record tensor shapesprofile_memory(bool): Whether to profile memory usage**profiler_kwargs: Additional PyTorch profiler arguments
kandc.capture_model_instance()
Wrap an existing model instance for profiling.
model_instance: The model instance to wrapmodel_name(str, optional): Name for the model tracesrecord_shapes(bool): Whether to record tensor shapesprofile_memory(bool): Whether to profile memory usage**profiler_kwargs: Additional profiler arguments
kandc.capture_trace()
Decorator to profile any function execution.
trace_name(str, optional): Name for the trace (defaults to function name)record_shapes(bool): Whether to record tensor shapesprofile_memory(bool): Whether to profile memory usage**profiler_kwargs: Additional profiler arguments
kandc.parse_model_trace()
Parse and analyze a model trace file.
trace_file(str): Path to the trace filemodel_name(str): Name of the model for analysis
None if parsing fails
Timing Functions
kandc.timed()
Decorator to time function execution.
name(str, optional): Name for the timing record (defaults to function name)
kandc.timed_call()
Time a function call without using a decorator.
name(str): Name for the timing recordfn(callable): Function to time*args: Positional arguments for the function**kwargs: Keyword arguments for the function
API Client (Advanced)
kandc.APIClient
Low-level API client for direct backend communication.
authenticate_with_browser(): Browser-based authenticationcreate_project(name, description, tags, metadata): Create new projectcreate_run(project_name, run_data): Create new runlog_metrics(run_id, metrics, step): Log metrics to runcreate_artifact(run_id, artifact_data, file_path): Upload artifactget_dashboard_url(project_id, run_id): Get dashboard URL
Authentication
kandc.get_api_key()
Get the current API key.
None if not authenticated
kandc.ensure_authenticated()
Ensure user is authenticated, prompting if necessary.
Run Object
TheRun object represents an active experiment run.
Properties
run.id(str): Unique run identifierrun.name(str): Run namerun.project(str): Project namerun.dir(Path): Local directory for run data
Methods
run.log(data, x): Log metrics to this runrun.log_artifact(path, name): Log artifact filerun.finish(): Finish this runrun.get_dashboard_url(): Get dashboard URL for this runrun.open_dashboard(): Open dashboard in browser
Run Modes
Online Mode (Default)
- Full cloud functionality
- Real-time dashboard
- Authentication required
- Internet connection required
Offline Mode
- Local-only operation
- No authentication required
- No internet required
- Data saved to local directory
Disabled Mode
- No-op mode (zero overhead)
- All kandc calls do nothing
- Perfect for production deployment
Error Handling
kandc.APIError
Base exception for API-related errors.
kandc.AuthenticationError
Exception raised for authentication failures.
Example:
Code Snapshot Configuration
kandc automatically captures your source code for experiment reproducibility. You can control this behavior in several ways:Disable Code Capture Completely
Custom Exclude Patterns
Respect .gitignore
kandc automatically respects your.gitignore file. Add patterns there to exclude them from code capture:
What Gets Captured
- Default Inclusions
- Default Exclusions
Source Files:
- Python:
.py - JavaScript/TypeScript:
.js,.ts,.jsx,.tsx - Other languages:
.java,.cpp,.c,.go,.rs,.rb - Scripts:
.sh,.bash,.zsh,.ps1,.bat - Config:
.yaml,.yml,.json,.toml,.ini - Documentation:
.md,.rst,.txt
requirements.txt,pyproject.tomlpackage.json,Dockerfile.gitignore,.env.example
Environment Variables for Code Capture
Environment Variables
Configure kandc behavior via environment variables: Core Configuration:KANDC_BACKEND_URL: Backend server URLKANDC_PROJECT: Default project nameKANDC_MODE: Default run mode (“online”, “offline”, “disabled”)KANDC_API_KEY: API key for authentication
KANDC_PROFILER_DISABLED: Disable PyTorch profiler (“1” to disable)
KANDC_CAPTURE_CODE: Enable/disable code capture (“true”, “false”)KANDC_CODE_EXCLUDE: Comma-separated exclude patternsKANDC_MAX_FILE_SIZE: Maximum file size in bytes for code capture

