# comet_mpm
Python SDK for [Comet Model Production Monitoring](https://www.comet.com/site/products/model-production-monitoring/)
## Installation
```shell
pip install comet_mpm --upgrade
```
To use these command-line functions, you'll need to have your Comet
API key set in one of the following two ways.
1. Environment variables (see below)
2. Directly as an argument to `comet_mpm.API(api_key="...")`
```
export COMET_API_KEY="YOUR-COMET-API-KEY"
```
## API Usage
The `comet_mpm` package provides a high-level API for interacting with Comet Model Production Monitoring. Here's how to get started:
### Initialization
```python
from comet_mpm import API
# Initialize with API key from environment variable
api = API()
# Or initialize with explicit API key
api = API(api_key="YOUR-COMET-API-KEY")
```
### Working with Models
#### Get a Model by Name
```python
# Get a specific model by workspace and model name
model = api.get_model_by_name("my-workspace", "my-model")
if model:
print(f"Model ID: {model.model_id}")
# Get model details
details = model.get_details()
print(f"Model details: {details}")
else:
print("Model not found")
```
#### Get the Default Model (Python Panel in Dashboard)
```python
# Get the default model configured for the current panel
model = api.get_model()
if model:
print(f"Default model ID: {model.model_id}")
else:
print("No default model configured")
```
### Model Analytics
Once you have a model instance, you can perform various analytics:
#### Prediction Counts
```python
# Get number of predictions for a time period
predictions_df = model.get_nb_predictions(
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY"
)
print(predictions_df)
```
#### Custom SQL Queries
```python
# Execute custom SQL queries
custom_metric_df = model.get_custom_metric(
sql="SELECT count(*) FROM model WHERE prediction > 0.5",
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY",
filters=["region=us-east", "version=1.0"],
model_version="1.0.0"
)
print(custom_metric_df)
```
#### Feature Analysis
```python
# Get available features
numerical_features = model.get_numerical_features()
categorical_features = model.get_categorical_features()
print(f"Numerical features: {numerical_features}")
print(f"Categorical features: {categorical_features}")
# Feature drift analysis
drift_df = model.get_feature_drift(
feature_name="age",
algorithm="EMD", # Options: "EMD", "PSI", "KL"
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY"
)
print(drift_df)
# Feature distribution for categorical features
distribution_df = model.get_feature_category_distribution(
feature_name="region",
normalize=True, # Return percentages instead of counts
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY"
)
print(distribution_df)
# Feature density for numerical features
density_df = model.get_feature_density(
feature_name="age",
start_date="2024-01-01",
end_date="2024-01-31"
)
print(density_df)
# Feature percentiles for numerical features
percentiles_df = model.get_feature_percentiles(
feature_name="age",
percentiles=[0, 0.25, 0.5, 0.75, 1.0],
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY"
)
print(percentiles_df)
```
### Panel Configuration
The API also provides access to panel configuration settings:
```python
# Get panel workspace
workspace = api.get_panel_workspace()
print(f"Panel workspace: {workspace}")
# Get panel dimensions
width = api.get_panel_width()
height = api.get_panel_height()
size = api.get_panel_size() # Returns (width, height) tuple
print(f"Panel size: {size}")
```
### Complete Example
```python
from comet_mpm import API
# Initialize API
api = API()
# Get a model
model = api.get_model_by_name("my-workspace", "fraud-detection-model")
if model:
# Get model details
details = model.get_details()
print(f"Model: {details['name']}")
# Analyze predictions over time
predictions = model.get_nb_predictions(
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY"
)
# Check feature drift for important features
for feature in ["transaction_amount", "user_age"]:
drift = model.get_feature_drift(
feature_name=feature,
algorithm="EMD",
start_date="2024-01-01",
end_date="2024-01-31"
)
print(f"Drift for {feature}: {drift}")
# Get custom metrics
fraud_rate = model.get_custom_metric(
sql="SELECT AVG(prediction) FROM model WHERE prediction > 0.5",
start_date="2024-01-01",
end_date="2024-01-31",
interval_type="DAILY"
)
print(f"Fraud rate over time: {fraud_rate}")
```
All methods return pandas DataFrames with metadata stored in the `.attrs` attribute, making it easy to track the parameters used for each query.
Raw data
{
"_id": null,
"home_page": "https://www.comet.ml",
"name": "comet-mpm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "comet_mpm",
"author": "Comet ML Inc.",
"author_email": "support@comet.com",
"download_url": "https://files.pythonhosted.org/packages/82/bc/7ba00e0052aa86ca8793b9ee556102b605229c793851c22f3b362d33d5b8/comet_mpm-1.4.2.tar.gz",
"platform": null,
"description": "# comet_mpm\n\nPython SDK for [Comet Model Production Monitoring](https://www.comet.com/site/products/model-production-monitoring/)\n\n## Installation\n\n```shell\npip install comet_mpm --upgrade\n```\n\nTo use these command-line functions, you'll need to have your Comet\nAPI key set in one of the following two ways.\n\n1. Environment variables (see below)\n2. Directly as an argument to `comet_mpm.API(api_key=\"...\")`\n\n```\nexport COMET_API_KEY=\"YOUR-COMET-API-KEY\"\n```\n\n## API Usage\n\nThe `comet_mpm` package provides a high-level API for interacting with Comet Model Production Monitoring. Here's how to get started:\n\n### Initialization\n\n```python\nfrom comet_mpm import API\n\n# Initialize with API key from environment variable\napi = API()\n\n# Or initialize with explicit API key\napi = API(api_key=\"YOUR-COMET-API-KEY\")\n```\n\n### Working with Models\n\n#### Get a Model by Name\n\n```python\n# Get a specific model by workspace and model name\nmodel = api.get_model_by_name(\"my-workspace\", \"my-model\")\n\nif model:\n print(f\"Model ID: {model.model_id}\")\n # Get model details\n details = model.get_details()\n print(f\"Model details: {details}\")\nelse:\n print(\"Model not found\")\n```\n\n#### Get the Default Model (Python Panel in Dashboard)\n\n```python\n# Get the default model configured for the current panel\nmodel = api.get_model()\n\nif model:\n print(f\"Default model ID: {model.model_id}\")\nelse:\n print(\"No default model configured\")\n```\n\n### Model Analytics\n\nOnce you have a model instance, you can perform various analytics:\n\n#### Prediction Counts\n\n```python\n# Get number of predictions for a time period\npredictions_df = model.get_nb_predictions(\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\"\n)\nprint(predictions_df)\n```\n\n#### Custom SQL Queries\n\n```python\n# Execute custom SQL queries\ncustom_metric_df = model.get_custom_metric(\n sql=\"SELECT count(*) FROM model WHERE prediction > 0.5\",\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\",\n filters=[\"region=us-east\", \"version=1.0\"],\n model_version=\"1.0.0\"\n)\nprint(custom_metric_df)\n```\n\n#### Feature Analysis\n\n```python\n# Get available features\nnumerical_features = model.get_numerical_features()\ncategorical_features = model.get_categorical_features()\nprint(f\"Numerical features: {numerical_features}\")\nprint(f\"Categorical features: {categorical_features}\")\n\n# Feature drift analysis\ndrift_df = model.get_feature_drift(\n feature_name=\"age\",\n algorithm=\"EMD\", # Options: \"EMD\", \"PSI\", \"KL\"\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\"\n)\nprint(drift_df)\n\n# Feature distribution for categorical features\ndistribution_df = model.get_feature_category_distribution(\n feature_name=\"region\",\n normalize=True, # Return percentages instead of counts\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\"\n)\nprint(distribution_df)\n\n# Feature density for numerical features\ndensity_df = model.get_feature_density(\n feature_name=\"age\",\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\"\n)\nprint(density_df)\n\n# Feature percentiles for numerical features\npercentiles_df = model.get_feature_percentiles(\n feature_name=\"age\",\n percentiles=[0, 0.25, 0.5, 0.75, 1.0],\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\"\n)\nprint(percentiles_df)\n```\n\n### Panel Configuration\n\nThe API also provides access to panel configuration settings:\n\n```python\n# Get panel workspace\nworkspace = api.get_panel_workspace()\nprint(f\"Panel workspace: {workspace}\")\n\n# Get panel dimensions\nwidth = api.get_panel_width()\nheight = api.get_panel_height()\nsize = api.get_panel_size() # Returns (width, height) tuple\nprint(f\"Panel size: {size}\")\n```\n\n### Complete Example\n\n```python\nfrom comet_mpm import API\n\n# Initialize API\napi = API()\n\n# Get a model\nmodel = api.get_model_by_name(\"my-workspace\", \"fraud-detection-model\")\n\nif model:\n # Get model details\n details = model.get_details()\n print(f\"Model: {details['name']}\")\n\n # Analyze predictions over time\n predictions = model.get_nb_predictions(\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\"\n )\n\n # Check feature drift for important features\n for feature in [\"transaction_amount\", \"user_age\"]:\n drift = model.get_feature_drift(\n feature_name=feature,\n algorithm=\"EMD\",\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\"\n )\n print(f\"Drift for {feature}: {drift}\")\n\n # Get custom metrics\n fraud_rate = model.get_custom_metric(\n sql=\"SELECT AVG(prediction) FROM model WHERE prediction > 0.5\",\n start_date=\"2024-01-01\",\n end_date=\"2024-01-31\",\n interval_type=\"DAILY\"\n )\n print(f\"Fraud rate over time: {fraud_rate}\")\n```\n\nAll methods return pandas DataFrames with metadata stored in the `.attrs` attribute, making it easy to track the parameters used for each query.\n",
"bugtrack_url": null,
"license": "Proprietary",
"summary": "Comet MPM SDK",
"version": "1.4.2",
"project_urls": {
"Homepage": "https://www.comet.ml"
},
"split_keywords": [
"comet_mpm"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a0f9c885a6515ab7fa3669eace8d0229ac38f64b397a9c5d7ea7da22d398b613",
"md5": "fdb132e02468d701b77a554ff05f2e8c",
"sha256": "30865e65ee0932427c6df6da6e12d34d0f077043639272aacdcce45b5d1223b0"
},
"downloads": -1,
"filename": "comet_mpm-1.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fdb132e02468d701b77a554ff05f2e8c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 68548,
"upload_time": "2025-08-19T12:42:16",
"upload_time_iso_8601": "2025-08-19T12:42:16.138552Z",
"url": "https://files.pythonhosted.org/packages/a0/f9/c885a6515ab7fa3669eace8d0229ac38f64b397a9c5d7ea7da22d398b613/comet_mpm-1.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "82bc7ba00e0052aa86ca8793b9ee556102b605229c793851c22f3b362d33d5b8",
"md5": "eb47dd80c363747e310ec551f9b24f48",
"sha256": "b90cce4abd95ef1f508f44a702cac65329cb9758e03346d740838205f1e7053a"
},
"downloads": -1,
"filename": "comet_mpm-1.4.2.tar.gz",
"has_sig": false,
"md5_digest": "eb47dd80c363747e310ec551f9b24f48",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 44996,
"upload_time": "2025-08-19T12:42:17",
"upload_time_iso_8601": "2025-08-19T12:42:17.376125Z",
"url": "https://files.pythonhosted.org/packages/82/bc/7ba00e0052aa86ca8793b9ee556102b605229c793851c22f3b362d33d5b8/comet_mpm-1.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-19 12:42:17",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "comet-mpm"
}