hectiq-console


Namehectiq-console JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://console.hectiq.ai
SummaryPython client to use the Hectiq Console
upload_time2024-04-17 13:24:47
maintainerNone
docs_urlNone
authorEdward Laurence
requires_pythonNone
licenseNone
keywords pip requirements imports
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Hectiq Console <!-- omit in toc -->

## Overview

The Hectiq Console Python Client is a comprehensive toolkit designed to interact with the Hectiq Console, a platform for managing various resources and incidents. This client provides functionalities to authenticate, manage resources, create incidents, handle files, and track metrics within the Hectiq environment.

**This service is for Hectiq's client only.**

- [Overview](#overview)
- [Middleware for API](#middleware-for-api)
  - [Installation](#installation)
  - [Starlette](#starlette)
  - [FastAPI](#fastapi)
  - [Send metrics](#send-metrics)
  - [Send annotations](#send-annotations)
- [Functional for workers](#functional-for-workers)
  - [Features](#features)
  - [Installation](#installation-1)
  - [Authentication](#authentication)
    - [Command Line Interface](#command-line-interface)
    - [Credential Storage](#credential-storage)
  - [Managing Resources](#managing-resources)
  - [Creating Incidents](#creating-incidents)
  - [File Handling](#file-handling)
  - [Metrics](#metrics)
  - [Annotations](#annotations)
  - [Timing Code Execution](#timing-code-execution)
- [Contact](#contact)

## Middleware for API

### Installation

```bash
pip install --upgrade 'hectiq-console[starlette]'
```

### Starlette 
Below is an example how to use the middleware for Starlette application. 

```python
from starlette.applications import Starlette
from starlette.middleware import Middleware
from hectiq_console.starlette import HectiqConsoleStarletteMiddleware
middleware = [
    Middleware(HectiqConsoleStarletteMiddleware, 
                resource="hectiq-test")
]
app = Starlette(middleware=middleware)
```
### FastAPI

Below is an example how to use the middleware for FastAPI. It shares the same Middleware as Starlette.

```python
import time
import random
from fastapi import FastAPI, Request
from hectiq_console.starlette import HectiqConsoleStarletteMiddleware, store_metrics

app = FastAPI(title="Demo application")
app.add_middleware(HectiqConsoleStarletteMiddleware, 
                   resource="hectiq-demo",
                   include_paths=["/predict"])

@app.get("/")
async def root():
    return {"message": "🚨 This route is not monitored by the hectiq console."}

@app.get("/predict")
async def root(request: Request):
    # Store a random number
    return {"message": "✅ This route is monitored by the hectiq console."}
```

### Send metrics

By default, the middleware stores the latency and counts of the monitored requests. You may add other metrics using the `store_metrics` in a request handler.

```python
@app.get("/predict")
async def root(request: Request):
    store_metrics(request=request, key=metrics_key, value=metrics_value)
```
You can send as many metrics in the same request as you want. However, if you use the same key in the same request, the previous value is overwritten by the new one.

> Do not forget to create the metrics definition in the console beforehand. Otherwise, you'll get an error at handshake.

### Send annotations

Annotations are useful to track predictions in your application. For example, you may want to track the result of a model. Use the method `store_annotation`. You can send as many annotations as you want in the same request.

```python
@app.get("/predict")
async def root(request: Request):
    store_annotation(request=request, 
                        inputs={"y": [0,1,2,3,4], "x": [0,1,2,3,4]}, 
                        outputs={"y_true": [5,6,7,8], "y_pred": [5,6,7,8]}, 
                        label="high-accuracy",
                        metadata={"model": "demo-model", 
                                "accuracy": 0.89})
```

## Functional for workers


### Features

- **Authentication**: Securely authenticate with the Hectiq Console using API keys.
- **Resource Management**: Set and retrieve resources within the Hectiq Console.
- **Incident Management**: Create incidents with detailed descriptions and associated files.
- **File Handling**: Add files to resources and upload them to the Hectiq Console.
- **Metrics Tracking**: Add and manage metrics for resources.
- **Annotation Downloading**: Download annotations related to resources.
- **Code Timing**: Utilize a context manager to time code execution and add metrics to a resource.

### Installation

To use this client, ensure you have Python installed on your system. Install the package via pip:

```bash
pip install hectiq-console
```


### Authentication

#### Command Line Interface
Some requests require authentification. Run the CLI tool to authenticate:

```bash
hectiq-console authenticate
```

You'll be prompted to enter your email and password. The CLI tool will automatically generate and store a new API key for you. These steps are described below:

1. **Login**: Enter your email and password.
2. **API Key Alias**: Set an alias for your new API key. The default is your hostname.
3. **Select Organization**: Choose from the list of organizations associated with your account.
4. **API Key Generation**: Automatically generates and stores a new API key.

API Keys are associated with an organization. If you have access to multiple organizations, you will be prompted to select an organization. If you only have access to one organization, the CLI tool will automatically select it for you. 

Once you have a valid API key in the credentials file (or environment variable), you can use the client to make authenticated requests. If you have multiple organizations in your credentials file, you can switch organization using the `set_organization` method.

```python
import hectiq_console.functional as hc
hc.set_resource("demo-resource")
hc.set_organization("hectiq-ai") # Required if you have multiple organizations
is_logged = hc.authenticate() 
```

#### Credential Storage

The API key is stored locally in the `~/.hectiq-console/credentials.toml` file. This file is created if it does not exist. If you need to change the default location, you can set the `HECTIQ_CONSOLE_CREDENTIALS_FILE` environment variable to the path of your choice. 

You can also set the `HECTIQ_CONSOLE_API_KEY` environment variable to your API key. This variable is used by the client to authenticate requests. If the environment variable is set, the client will not use the credentials file.


### Managing Resources

Set your resource using the `set_resource` method. Place this method at the beginning of your script. It uses a ContextVar to store the resource. Therefore, you can use it in a multi-threaded environment. If you set the resource, it will be used for all requests. Otherwise, you'll need to specify the resource in each request.

```python
import hectiq_console.functional as hc
hc.set_resource("resource_id")
```

### Creating Incidents

Create incidents related to a resource:

```python
import hectiq_console.functional as hc
hc.create_incident(title="Incident Title", description="Detailed description")
```

You can also add files to the incident:

```python
import hectiq_console.functional as hc
hc.create_incident(title="Incident Title", 
                    description="Detailed description", 
                    filenames=["path/to/your/file"])
```

### File Handling

Add and upload files to a resource:

```python
import hectiq_console.functional as hc
hc.add_file("path/to/your/file")
```

### Metrics

Add metrics to a resource:

```python
import hectiq_console.functional as hc
hc.add_metrics(name="metric_name", value=123)
```

### Annotations
Download annotations related to a resource:

```python
import hectiq_console.functional as hc
annotation = hc.download_annotation("annotation_id")
```

### Timing Code Execution

Time a block of code execution:

```python
import hectiq_console.functional as hc
with hc.timer_context("timer_name"):
    # Your code here
    pass
```
The timer name is used as the metric name. The timer context manager automatically adds the metric to the resource. 

## Contact

For support or inquiries, please contact the project maintainer at [info@hectiq.ai].






            

Raw data

            {
    "_id": null,
    "home_page": "https://console.hectiq.ai",
    "name": "hectiq-console",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pip requirements imports",
    "author": "Edward Laurence",
    "author_email": "edwardl@hectiq.ai",
    "download_url": "https://files.pythonhosted.org/packages/46/49/8b66819f609f2c53ef531a5cfb87e2dd950ca9122664e754e1d36c366c52/hectiq_console-1.2.1.tar.gz",
    "platform": null,
    "description": "# Hectiq Console <!-- omit in toc -->\n\n## Overview\n\nThe Hectiq Console Python Client is a comprehensive toolkit designed to interact with the Hectiq Console, a platform for managing various resources and incidents. This client provides functionalities to authenticate, manage resources, create incidents, handle files, and track metrics within the Hectiq environment.\n\n**This service is for Hectiq's client only.**\n\n- [Overview](#overview)\n- [Middleware for API](#middleware-for-api)\n  - [Installation](#installation)\n  - [Starlette](#starlette)\n  - [FastAPI](#fastapi)\n  - [Send metrics](#send-metrics)\n  - [Send annotations](#send-annotations)\n- [Functional for workers](#functional-for-workers)\n  - [Features](#features)\n  - [Installation](#installation-1)\n  - [Authentication](#authentication)\n    - [Command Line Interface](#command-line-interface)\n    - [Credential Storage](#credential-storage)\n  - [Managing Resources](#managing-resources)\n  - [Creating Incidents](#creating-incidents)\n  - [File Handling](#file-handling)\n  - [Metrics](#metrics)\n  - [Annotations](#annotations)\n  - [Timing Code Execution](#timing-code-execution)\n- [Contact](#contact)\n\n## Middleware for API\n\n### Installation\n\n```bash\npip install --upgrade 'hectiq-console[starlette]'\n```\n\n### Starlette \nBelow is an example how to use the middleware for Starlette application. \n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.middleware import Middleware\nfrom hectiq_console.starlette import HectiqConsoleStarletteMiddleware\nmiddleware = [\n    Middleware(HectiqConsoleStarletteMiddleware, \n                resource=\"hectiq-test\")\n]\napp = Starlette(middleware=middleware)\n```\n### FastAPI\n\nBelow is an example how to use the middleware for FastAPI. It shares the same Middleware as Starlette.\n\n```python\nimport time\nimport random\nfrom fastapi import FastAPI, Request\nfrom hectiq_console.starlette import HectiqConsoleStarletteMiddleware, store_metrics\n\napp = FastAPI(title=\"Demo application\")\napp.add_middleware(HectiqConsoleStarletteMiddleware, \n                   resource=\"hectiq-demo\",\n                   include_paths=[\"/predict\"])\n\n@app.get(\"/\")\nasync def root():\n    return {\"message\": \"\ud83d\udea8 This route is not monitored by the hectiq console.\"}\n\n@app.get(\"/predict\")\nasync def root(request: Request):\n    # Store a random number\n    return {\"message\": \"\u2705 This route is monitored by the hectiq console.\"}\n```\n\n### Send metrics\n\nBy default, the middleware stores the latency and counts of the monitored requests. You may add other metrics using the `store_metrics` in a request handler.\n\n```python\n@app.get(\"/predict\")\nasync def root(request: Request):\n    store_metrics(request=request, key=metrics_key, value=metrics_value)\n```\nYou can send as many metrics in the same request as you want. However, if you use the same key in the same request, the previous value is overwritten by the new one.\n\n> Do not forget to create the metrics definition in the console beforehand. Otherwise, you'll get an error at handshake.\n\n### Send annotations\n\nAnnotations are useful to track predictions in your application. For example, you may want to track the result of a model. Use the method `store_annotation`. You can send as many annotations as you want in the same request.\n\n```python\n@app.get(\"/predict\")\nasync def root(request: Request):\n    store_annotation(request=request, \n                        inputs={\"y\": [0,1,2,3,4], \"x\": [0,1,2,3,4]}, \n                        outputs={\"y_true\": [5,6,7,8], \"y_pred\": [5,6,7,8]}, \n                        label=\"high-accuracy\",\n                        metadata={\"model\": \"demo-model\", \n                                \"accuracy\": 0.89})\n```\n\n## Functional for workers\n\n\n### Features\n\n- **Authentication**: Securely authenticate with the Hectiq Console using API keys.\n- **Resource Management**: Set and retrieve resources within the Hectiq Console.\n- **Incident Management**: Create incidents with detailed descriptions and associated files.\n- **File Handling**: Add files to resources and upload them to the Hectiq Console.\n- **Metrics Tracking**: Add and manage metrics for resources.\n- **Annotation Downloading**: Download annotations related to resources.\n- **Code Timing**: Utilize a context manager to time code execution and add metrics to a resource.\n\n### Installation\n\nTo use this client, ensure you have Python installed on your system. Install the package via pip:\n\n```bash\npip install hectiq-console\n```\n\n\n### Authentication\n\n#### Command Line Interface\nSome requests require authentification. Run the CLI tool to authenticate:\n\n```bash\nhectiq-console authenticate\n```\n\nYou'll be prompted to enter your email and password. The CLI tool will automatically generate and store a new API key for you. These steps are described below:\n\n1. **Login**: Enter your email and password.\n2. **API Key Alias**: Set an alias for your new API key. The default is your hostname.\n3. **Select Organization**: Choose from the list of organizations associated with your account.\n4. **API Key Generation**: Automatically generates and stores a new API key.\n\nAPI Keys are associated with an organization. If you have access to multiple organizations, you will be prompted to select an organization. If you only have access to one organization, the CLI tool will automatically select it for you. \n\nOnce you have a valid API key in the credentials file (or environment variable), you can use the client to make authenticated requests. If you have multiple organizations in your credentials file, you can switch organization using the `set_organization` method.\n\n```python\nimport hectiq_console.functional as hc\nhc.set_resource(\"demo-resource\")\nhc.set_organization(\"hectiq-ai\") # Required if you have multiple organizations\nis_logged = hc.authenticate() \n```\n\n#### Credential Storage\n\nThe API key is stored locally in the `~/.hectiq-console/credentials.toml` file. This file is created if it does not exist. If you need to change the default location, you can set the `HECTIQ_CONSOLE_CREDENTIALS_FILE` environment variable to the path of your choice. \n\nYou can also set the `HECTIQ_CONSOLE_API_KEY` environment variable to your API key. This variable is used by the client to authenticate requests. If the environment variable is set, the client will not use the credentials file.\n\n\n### Managing Resources\n\nSet your resource using the `set_resource` method. Place this method at the beginning of your script. It uses a ContextVar to store the resource. Therefore, you can use it in a multi-threaded environment. If you set the resource, it will be used for all requests. Otherwise, you'll need to specify the resource in each request.\n\n```python\nimport hectiq_console.functional as hc\nhc.set_resource(\"resource_id\")\n```\n\n### Creating Incidents\n\nCreate incidents related to a resource:\n\n```python\nimport hectiq_console.functional as hc\nhc.create_incident(title=\"Incident Title\", description=\"Detailed description\")\n```\n\nYou can also add files to the incident:\n\n```python\nimport hectiq_console.functional as hc\nhc.create_incident(title=\"Incident Title\", \n                    description=\"Detailed description\", \n                    filenames=[\"path/to/your/file\"])\n```\n\n### File Handling\n\nAdd and upload files to a resource:\n\n```python\nimport hectiq_console.functional as hc\nhc.add_file(\"path/to/your/file\")\n```\n\n### Metrics\n\nAdd metrics to a resource:\n\n```python\nimport hectiq_console.functional as hc\nhc.add_metrics(name=\"metric_name\", value=123)\n```\n\n### Annotations\nDownload annotations related to a resource:\n\n```python\nimport hectiq_console.functional as hc\nannotation = hc.download_annotation(\"annotation_id\")\n```\n\n### Timing Code Execution\n\nTime a block of code execution:\n\n```python\nimport hectiq_console.functional as hc\nwith hc.timer_context(\"timer_name\"):\n    # Your code here\n    pass\n```\nThe timer name is used as the metric name. The timer context manager automatically adds the metric to the resource. \n\n## Contact\n\nFor support or inquiries, please contact the project maintainer at [info@hectiq.ai].\n\n\n\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python client to use the Hectiq Console",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://console.hectiq.ai"
    },
    "split_keywords": [
        "pip",
        "requirements",
        "imports"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e0f2f6479dcf18fb81aa33188de8e9bf7536da278dc6c116b1ce8c75c045b07",
                "md5": "9dc635843170d95a3d74ef177a5dee64",
                "sha256": "0b22ada8e1c63a0037263bdabd6ac813967ed9a809d553c4d1289691775620cc"
            },
            "downloads": -1,
            "filename": "hectiq_console-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9dc635843170d95a3d74ef177a5dee64",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21747,
            "upload_time": "2024-04-17T13:24:46",
            "upload_time_iso_8601": "2024-04-17T13:24:46.181547Z",
            "url": "https://files.pythonhosted.org/packages/4e/0f/2f6479dcf18fb81aa33188de8e9bf7536da278dc6c116b1ce8c75c045b07/hectiq_console-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46498b66819f609f2c53ef531a5cfb87e2dd950ca9122664e754e1d36c366c52",
                "md5": "81d2030c964c167937576f35f04e6695",
                "sha256": "f12268f25c61cfeee8328991be68ccc0b0f5ffa0c73eefd7e449a50d0f46f6e7"
            },
            "downloads": -1,
            "filename": "hectiq_console-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "81d2030c964c167937576f35f04e6695",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 20862,
            "upload_time": "2024-04-17T13:24:47",
            "upload_time_iso_8601": "2024-04-17T13:24:47.946017Z",
            "url": "https://files.pythonhosted.org/packages/46/49/8b66819f609f2c53ef531a5cfb87e2dd950ca9122664e754e1d36c366c52/hectiq_console-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-17 13:24:47",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "hectiq-console"
}
        
Elapsed time: 0.26657s