PyPromql


NamePyPromql JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/aviv-levi/pypromql.git
SummaryPyPromql is a Python library that simplifies the creation and execution of PromQL queries.
upload_time2023-06-14 20:38:19
maintainer
docs_urlNone
authorAviv Levi
requires_python
licenseMIT
keywords pypromql py-promql prometheus-query-builder promql-query-builder
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            PyPromql - Python PromQL Query Builder
=======================================

# Abstract

###  What is PyPromql?

PyPromql is a Python library that simplifies the creation and execution of PromQL queries.
With PyPromql, developers can effortlessly construct and run PromQL queries with ease and simplicity.
It provides a convenient and intuitive interface for working with Prometheus Query Language (PromQL).

Read the docs: http://pypromql.readthedocs.io/en/latest/

# Installation

To install PyPromql run the following command:

```bash
    pip install pypromql
```

# Tutorial
The main classes in pypromql are ``pypromql.query.Query`` and ``pypromql.result.PrometheusResult``.

```python
    from pypromql.query import Query
    from pypromql.result import PrometheusResult
```

## Create simple query

The entry point for building queries is ``pypromql.query.Query``.

```python
    promql_query = Query.metric('up').label('job', 'prometheus')
```

```promql
    up{job="prometheus"}
```

To convert the query into raw PromQL, it can be cast to a string.

```python
    str(promql_query)
```
Alternatively, you can use the `to_promql()` function:

```python
    promql_query.to_promql()
```

## Execute query

First, we need to create a ``pypromql.PrometheusConnection``.

```python
    connection = PrometheusConnection(prometheus_base_url='http://my-host-name:my-port/')
```    
Then, we execute our query and get the result using ``PrometheusResult.from_query_builder``.

```python
    result = PrometheusResult.from_query_builder(promql_query, connection)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aviv-levi/pypromql.git",
    "name": "PyPromql",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pypromql,py-promql,prometheus-query-builder,promql-query-builder",
    "author": "Aviv Levi",
    "author_email": "60aviv60@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f8/20/8d26868ec88ee50de37e8a71196a047a391172e59b736a52ede60aca9ac6/PyPromql-0.0.3.tar.gz",
    "platform": null,
    "description": "PyPromql - Python PromQL Query Builder\r\n=======================================\r\n\r\n# Abstract\r\n\r\n###  What is PyPromql?\r\n\r\nPyPromql is a Python library that simplifies the creation and execution of PromQL queries.\r\nWith PyPromql, developers can effortlessly construct and run PromQL queries with ease and simplicity.\r\nIt provides a convenient and intuitive interface for working with Prometheus Query Language (PromQL).\r\n\r\nRead the docs: http://pypromql.readthedocs.io/en/latest/\r\n\r\n# Installation\r\n\r\nTo install PyPromql run the following command:\r\n\r\n```bash\r\n    pip install pypromql\r\n```\r\n\r\n# Tutorial\r\nThe main classes in pypromql are ``pypromql.query.Query`` and ``pypromql.result.PrometheusResult``.\r\n\r\n```python\r\n    from pypromql.query import Query\r\n    from pypromql.result import PrometheusResult\r\n```\r\n\r\n## Create simple query\r\n\r\nThe entry point for building queries is ``pypromql.query.Query``.\r\n\r\n```python\r\n    promql_query = Query.metric('up').label('job', 'prometheus')\r\n```\r\n\r\n```promql\r\n    up{job=\"prometheus\"}\r\n```\r\n\r\nTo convert the query into raw PromQL, it can be cast to a string.\r\n\r\n```python\r\n    str(promql_query)\r\n```\r\nAlternatively, you can use the `to_promql()` function:\r\n\r\n```python\r\n    promql_query.to_promql()\r\n```\r\n\r\n## Execute query\r\n\r\nFirst, we need to create a ``pypromql.PrometheusConnection``.\r\n\r\n```python\r\n    connection = PrometheusConnection(prometheus_base_url='http://my-host-name:my-port/')\r\n```    \r\nThen, we execute our query and get the result using ``PrometheusResult.from_query_builder``.\r\n\r\n```python\r\n    result = PrometheusResult.from_query_builder(promql_query, connection)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PyPromql is a Python library that simplifies the creation and execution of PromQL queries.",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/aviv-levi/pypromql.git"
    },
    "split_keywords": [
        "pypromql",
        "py-promql",
        "prometheus-query-builder",
        "promql-query-builder"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76775d8716c4641af116b32567c5d2d57869ac4a1e3435c3369263a5ee6a4549",
                "md5": "dd207de44dfca72df2343d47575f0eed",
                "sha256": "7dad162b6e67c0b95cf54b34d8af8061fac1b244a1ebc6adc0f02927250ed11e"
            },
            "downloads": -1,
            "filename": "PyPromql-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dd207de44dfca72df2343d47575f0eed",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9452,
            "upload_time": "2023-06-14T20:38:15",
            "upload_time_iso_8601": "2023-06-14T20:38:15.486040Z",
            "url": "https://files.pythonhosted.org/packages/76/77/5d8716c4641af116b32567c5d2d57869ac4a1e3435c3369263a5ee6a4549/PyPromql-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f8208d26868ec88ee50de37e8a71196a047a391172e59b736a52ede60aca9ac6",
                "md5": "596ac33a670531d807e6db4168ca2fe8",
                "sha256": "da814b6f704c994f15cd331fc7588195497b2adbc32ee072239c7dc73af8d108"
            },
            "downloads": -1,
            "filename": "PyPromql-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "596ac33a670531d807e6db4168ca2fe8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6960,
            "upload_time": "2023-06-14T20:38:19",
            "upload_time_iso_8601": "2023-06-14T20:38:19.005376Z",
            "url": "https://files.pythonhosted.org/packages/f8/20/8d26868ec88ee50de37e8a71196a047a391172e59b736a52ede60aca9ac6/PyPromql-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-14 20:38:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aviv-levi",
    "github_project": "pypromql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pypromql"
}
        
Elapsed time: 0.11366s