{"id":3935,"library":"comet-ml","title":"Comet ML","description":"Comet ML is an MLOps platform for tracking, comparing, debugging, and optimizing machine learning models. It provides a comprehensive dashboard to visualize experiments, log code, metrics, hyperparameters, and artifacts. The current version is 3.57.3, and it receives frequent updates with new features and bug fixes.","status":"active","version":"3.57.3","language":"python","source_language":"en","source_url":"https://github.com/comet-ml/comet-ml-py","tags":["mlops","experiment-tracking","machine-learning","logging","data-science"],"install":[{"cmd":"pip install comet_ml","lang":"bash","label":"Install core library"}],"dependencies":[],"imports":[{"note":"While functional, importing directly from the top-level package is the standard and recommended approach.","wrong":"from comet_ml.experiment import Experiment","symbol":"Experiment","correct":"from comet_ml import Experiment"},{"note":"The `init` function is typically called as a method of the top-level `comet_ml` module, not directly imported.","wrong":"from comet_ml import init","symbol":"init","correct":"import comet_ml; comet_ml.init()"},{"note":"Logging functions are methods of an `Experiment` object, not global functions on the `comet_ml` module (unless using the simpler `comet_ml.init()` pattern).","wrong":"comet_ml.log_parameters({'param': value})","symbol":"log_parameters","correct":"experiment.log_parameters({'param': value})"}],"quickstart":{"code":"import os\nfrom comet_ml import Experiment\n\n# Ensure COMET_API_KEY and COMET_WORKSPACE are set as environment variables\n# or use comet_ml.login() if you prefer interactive login.\n# For example: os.environ['COMET_API_KEY'] = 'YOUR_API_KEY'\n# os.environ['COMET_WORKSPACE'] = 'YOUR_WORKSPACE'\n\n# Or, for local testing without an explicit API key (results only stored locally):\n# experiment = Experiment(project_name=\"my-test-project\", log_code=False, display_summary_to_terminal=False)\n\n# Initialize an experiment\n# It's best practice to use a context manager to ensure the experiment terminates correctly\nwith Experiment(project_name=\"my-quickstart-project\", \n                api_key=os.environ.get('COMET_API_KEY', None),\n                workspace=os.environ.get('COMET_WORKSPACE', None),\n                auto_output_logging='simple', # capture print statements\n                auto_metric_logging=True, # capture common metrics\n                log_code=True # logs your script code\n               ) as experiment:\n    # Log hyperparameters\n    hyper_params = {\"learning_rate\": 0.001, \"epochs\": 10, \"batch_size\": 32}\n    experiment.log_parameters(hyper_params)\n\n    # Simulate a training loop\n    for epoch in range(hyper_params[\"epochs\"]):\n        # Simulate metric calculation\n        accuracy = 0.5 + (epoch * 0.05) + (hyper_params[\"learning_rate\"] * 100)\n        loss = 1.0 - (epoch * 0.08) - (hyper_params[\"learning_rate\"] * 50)\n\n        # Log metrics for each epoch\n        experiment.log_metric(\"accuracy\", accuracy, step=epoch)\n        experiment.log_metric(\"loss\", loss, step=epoch)\n\n    # Log a final metric or result\n    final_accuracy = accuracy # from the last epoch\n    experiment.log_metric(\"final_accuracy\", final_accuracy)\n\n    print(f\"Experiment URL: {experiment.url}\")\n\nprint(\"Experiment finished.\")\n","lang":"python","description":"This quickstart demonstrates how to create an `Experiment` using a context manager, log hyperparameters, and track metrics during a simulated training loop. It leverages environment variables for authentication, which is a recommended best practice."},"warnings":[{"fix":"Set `COMET_API_KEY` and `COMET_WORKSPACE` as environment variables or call `comet_ml.login()` once to store credentials locally.","message":"Comet API Key and Workspace configuration: Hardcoding API keys directly in scripts is a security risk. Best practice is to use environment variables (`COMET_API_KEY`, `COMET_WORKSPACE`), a `.comet.config` file, or `comet_ml.login()` for interactive setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `with Experiment(...) as experiment:` for new experiments to ensure proper lifecycle management and resource cleanup, especially in scripts that might crash.","message":"Experiment lifecycle management: Forgetting to end an experiment (e.g., in case of script errors) can lead to hanging processes or incomplete experiment data. Using the `Experiment` class as a context manager (`with Experiment(...) as experiment:`) automatically handles experiment termination.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to 3.8 or newer. If you must use an older Python version, consider pinning `comet_ml` to a 2.x version (though not recommended due to lack of updates).","message":"Python 2.x support dropped: Comet ML version 3.x and above requires Python 3.8 or higher. Attempts to use it with older Python versions will result in `ModuleNotFoundError` or `SyntaxError`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review the documentation for `Experiment` initialization parameters like `auto_output_logging`, `auto_metric_logging`, `log_code`, `log_git_metadata` to explicitly enable or disable automatic logging features as needed for your specific use case.","message":"Automatic logging features: Comet ML automatically logs many aspects (e.g., environment details, code, git data, common metrics like loss/accuracy from popular ML frameworks). This can be helpful but might log more than desired or conflict with manual logging if not understood. For example, `auto_output_logging` can capture stdout/stderr.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'3.57.3':36 'artifact':31 'bug':46 'code':27 'comet':1,3 'compar':11 'comprehens':21 'current':33 'dashboard':22 'data':57 'data-sci':56 'debug':12 'experi':25,50 'experiment-track':49 'featur':44 'fix':47 'frequent':40 'hyperparamet':29 'learn':16,54 'log':26,55 'machin':15,53 'machine-learn':52 'metric':28 'ml':2,4 'mlop':7,48 'model':17 'new':43 'optim':14 'platform':8 'provid':19 'receiv':39 'scienc':58 'track':10,51 'updat':41 'version':34 'visual':24","created_at":"2026-04-12T03:33:56.540855+00:00","updated_at":"2026-04-16T03:13:04.565774+00:00","problems":[{"fix":"Install the package using pip: `pip install comet-ml`. If using conda, use `conda install -c anaconda -c conda-forge -c comet_ml comet_ml`.","cause":"The `comet-ml` Python package is not installed in the current environment or the environment is not correctly activated.","error":"ModuleNotFoundError: No module named 'comet_ml'"},{"fix":"Move `import comet_ml` to the very top of your Python script, before any other machine learning framework imports. Alternatively, disable auto-logging by setting the environment variable `COMET_DISABLE_AUTO_LOGGING=1`.","cause":"The `comet_ml` library was imported after one of the supported machine learning frameworks (e.g., TensorFlow, PyTorch, Keras, fastai), interfering with Comet's automatic logging hooks.","error":"ImportError: Please import comet before importing these modules: ..."},{"fix":"Check your internet connection and ensure your Comet API key is correctly configured. You can configure it using `comet_ml.login()`, by setting the `COMET_API_KEY` environment variable, or in your `~/.comet.config` file.","cause":"The Comet SDK failed to establish an initial connection or handshake with the Comet server, often due to network issues, an incorrect or missing API key, or server downtime.","error":"COMET ERROR: Run will not be logged"},{"fix":"Ensure the `Experiment` object is properly initialized and active before calling its methods. Check for earlier errors that might have prevented `Experiment` creation. Consider using `comet_ml.error_mode()` to get full tracebacks and `comet_ml.get_running_experiment()` to safely retrieve an existing experiment.","cause":"The `Experiment` object was not successfully initialized or was prematurely terminated, leading to attempts to call methods on a `None` object.","error":"AttributeError: 'NoneType' object has no attribute '...' (when interacting with an Experiment object)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.58.6","cli_name":"comet","cli_version":"numpy not installed; some functionality will be unavailable","type":"library","homepage":"https://www.comet.com","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/comet-ml/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","observability","workflow"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}