hectiq-console


Namehectiq-console JSON
Version 1.2.4 PyPI version JSON
download
home_pagehttps://console.hectiq.ai
SummaryPython client to use the Hectiq Console
upload_time2024-05-14 19:15:07
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/9d/3f/4af25bc248f34e327ef8225ced4139a06cf40171d097fcdd21acdfb0778c/hectiq_console-1.2.4.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.4",
    "project_urls": {
        "Homepage": "https://console.hectiq.ai"
    },
    "split_keywords": [
        "pip",
        "requirements",
        "imports"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "86395069cac06bc81ec501586b12106519b9aae4730612d486f46a0d8c83b29c",
                "md5": "ef7ad13ded827f99dde995e815d42c8b",
                "sha256": "5efc69b8c5fe72e150f421e7025db091fbba4e7e79b244cca129c2b8b1e7d1d3"
            },
            "downloads": -1,
            "filename": "hectiq_console-1.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ef7ad13ded827f99dde995e815d42c8b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 22097,
            "upload_time": "2024-05-14T19:15:06",
            "upload_time_iso_8601": "2024-05-14T19:15:06.265955Z",
            "url": "https://files.pythonhosted.org/packages/86/39/5069cac06bc81ec501586b12106519b9aae4730612d486f46a0d8c83b29c/hectiq_console-1.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d3f4af25bc248f34e327ef8225ced4139a06cf40171d097fcdd21acdfb0778c",
                "md5": "da48885ecca3bf9b0b2867324621b664",
                "sha256": "e43a50eb20fb6f8aa2f8779454b7e592a2333fe589eaebb038b6c21598d80ec8"
            },
            "downloads": -1,
            "filename": "hectiq_console-1.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "da48885ecca3bf9b0b2867324621b664",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21169,
            "upload_time": "2024-05-14T19:15:07",
            "upload_time_iso_8601": "2024-05-14T19:15:07.490701Z",
            "url": "https://files.pythonhosted.org/packages/9d/3f/4af25bc248f34e327ef8225ced4139a06cf40171d097fcdd21acdfb0778c/hectiq_console-1.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-14 19:15:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "hectiq-console"
}
        
Elapsed time: 2.94414s