dm-aioinfluxdb


Namedm-aioinfluxdb JSON
Version 0.2.7 PyPI version JSON
download
home_pagehttps://pypi.org/project/dm-aioinfluxdb
SummaryThis is my custom aioinfluxdb client
upload_time2024-10-21 10:29:28
maintainerNone
docs_urlNone
authordimka4621
requires_python>=3.8
licenseNone
keywords dm aioinfluxdb
VCS
bugtrack_url
requirements dm-logger aiohttp aiocsv influxdb-client
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DM-aioinfluxdb

## Urls

* [PyPI](https://pypi.org/project/dm-aioinfluxdb)
* [GitHub](https://github.com/MykhLibs/dm-aioinfluxdb)

## Usage

### Write

```python
from dm_aioinfluxdb import DMAioInfluxDBClient
import asyncio


async def main():
    # create client
    influxdb_client = DMAioInfluxDBClient("localhost", 8086, "org", "token")

    # create influxdb points
    point1 = influxdb_client.create_point("example-measurement", {"value": 1.5}, {"tag1": "tag1-value"})
    # or
    point2 = DMAioInfluxDBClient.create_point("example-measurement", {"value": 0}, {"tag2": "tag2-value"})

    # write one or more points
    await influxdb_client.write("example-bucket", point1)
    # write line protocol record
    record = "example-measurement,tag1=tag1-value, value=1.5 1713162515"
    await influxdb_client.write("example-bucket", record)

    # type: bool
    status = await influxdb_client.write("example-bucket", [point1, point2])

    # return error message in case of error
    # type: (bool, str)
    status, err_msg = await influxdb_client.write("example-bucket", point1, return_errors=True)

    # without error logs in case of errors
    await influxdb_client.write("example-bucket", point1, err_logging=False)

if __name__ == "__main__":
    asyncio.run(main())
```

### Query

```python
from dm_aioinfluxdb import DMAioInfluxDBClient
import asyncio


async def main():
    # create client
    influxdb_client = DMAioInfluxDBClient("localhost", 8086, "org", "token")

    # write query
    query = 'from(bucket: "example") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "monitoring" and r._field == "cpu")'

    # type: <class 'influxdb_client.client.flux_table.TableList'>
    table_res = await influxdb_client.query(query)
    # type: str
    json_res = await influxdb_client.query(query, to="json")
    # type: list[dict]
    list_res = await influxdb_client.query(query, to="list")

    # return error message in case of error
    # type: (str, str)
    json_res, err_msg = await influxdb_client.query(query, to="json", return_errors=True)

    # without error logs in case of errors
    res = await influxdb_client.query(query, err_logging=False)


if __name__ == "__main__":
    asyncio.run(main())
```

### Set custom logger

_If you want set up custom logger_

```python
from dm_aioinfluxdb import DMAioInfluxDBClient


# create custom logger
class MyLogger:
    def debug(self, message):
        pass

    def info(self, message):
        pass

    def warning(self, message):
        print(message)

    def error(self, message):
        print(message)


# set up custom logger for all clients
DMAioInfluxDBClient.set_logger(MyLogger())
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/dm-aioinfluxdb",
    "name": "dm-aioinfluxdb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "dm aioinfluxdb",
    "author": "dimka4621",
    "author_email": "mismartconfig@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/5c/123cbc4461c1df50fa6882ea99daf666617e3d6842eb29f36db2e95f70f8/dm_aioinfluxdb-0.2.7.tar.gz",
    "platform": null,
    "description": "# DM-aioinfluxdb\n\n## Urls\n\n* [PyPI](https://pypi.org/project/dm-aioinfluxdb)\n* [GitHub](https://github.com/MykhLibs/dm-aioinfluxdb)\n\n## Usage\n\n### Write\n\n```python\nfrom dm_aioinfluxdb import DMAioInfluxDBClient\nimport asyncio\n\n\nasync def main():\n    # create client\n    influxdb_client = DMAioInfluxDBClient(\"localhost\", 8086, \"org\", \"token\")\n\n    # create influxdb points\n    point1 = influxdb_client.create_point(\"example-measurement\", {\"value\": 1.5}, {\"tag1\": \"tag1-value\"})\n    # or\n    point2 = DMAioInfluxDBClient.create_point(\"example-measurement\", {\"value\": 0}, {\"tag2\": \"tag2-value\"})\n\n    # write one or more points\n    await influxdb_client.write(\"example-bucket\", point1)\n    # write line protocol record\n    record = \"example-measurement,tag1=tag1-value, value=1.5 1713162515\"\n    await influxdb_client.write(\"example-bucket\", record)\n\n    # type: bool\n    status = await influxdb_client.write(\"example-bucket\", [point1, point2])\n\n    # return error message in case of error\n    # type: (bool, str)\n    status, err_msg = await influxdb_client.write(\"example-bucket\", point1, return_errors=True)\n\n    # without error logs in case of errors\n    await influxdb_client.write(\"example-bucket\", point1, err_logging=False)\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### Query\n\n```python\nfrom dm_aioinfluxdb import DMAioInfluxDBClient\nimport asyncio\n\n\nasync def main():\n    # create client\n    influxdb_client = DMAioInfluxDBClient(\"localhost\", 8086, \"org\", \"token\")\n\n    # write query\n    query = 'from(bucket: \"example\") |> range(start: -1h) |> filter(fn: (r) => r._measurement == \"monitoring\" and r._field == \"cpu\")'\n\n    # type: <class 'influxdb_client.client.flux_table.TableList'>\n    table_res = await influxdb_client.query(query)\n    # type: str\n    json_res = await influxdb_client.query(query, to=\"json\")\n    # type: list[dict]\n    list_res = await influxdb_client.query(query, to=\"list\")\n\n    # return error message in case of error\n    # type: (str, str)\n    json_res, err_msg = await influxdb_client.query(query, to=\"json\", return_errors=True)\n\n    # without error logs in case of errors\n    res = await influxdb_client.query(query, err_logging=False)\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### Set custom logger\n\n_If you want set up custom logger_\n\n```python\nfrom dm_aioinfluxdb import DMAioInfluxDBClient\n\n\n# create custom logger\nclass MyLogger:\n    def debug(self, message):\n        pass\n\n    def info(self, message):\n        pass\n\n    def warning(self, message):\n        print(message)\n\n    def error(self, message):\n        print(message)\n\n\n# set up custom logger for all clients\nDMAioInfluxDBClient.set_logger(MyLogger())\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This is my custom aioinfluxdb client",
    "version": "0.2.7",
    "project_urls": {
        "GitHub": "https://github.com/MykhLibs/dm-aioinfluxdb",
        "Homepage": "https://pypi.org/project/dm-aioinfluxdb"
    },
    "split_keywords": [
        "dm",
        "aioinfluxdb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a99b1823ad05d9cb582a359d8054d9132816b8dfb349f006fdc2ab5bb29f5b4",
                "md5": "780ad7707c1e344485015404851a776e",
                "sha256": "c2f1636b9216ce731f53d6dc43df0409c7aeab0e3656a83b03e4912f5a1ceaee"
            },
            "downloads": -1,
            "filename": "dm_aioinfluxdb-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "780ad7707c1e344485015404851a776e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4019,
            "upload_time": "2024-10-21T10:29:27",
            "upload_time_iso_8601": "2024-10-21T10:29:27.265641Z",
            "url": "https://files.pythonhosted.org/packages/5a/99/b1823ad05d9cb582a359d8054d9132816b8dfb349f006fdc2ab5bb29f5b4/dm_aioinfluxdb-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "335c123cbc4461c1df50fa6882ea99daf666617e3d6842eb29f36db2e95f70f8",
                "md5": "45e0c9db8145a38bff94bf66477593bd",
                "sha256": "b7642ae8617e5b44fa35bc0f5550286a9d9d7e6963eb6b7b640369601517f22b"
            },
            "downloads": -1,
            "filename": "dm_aioinfluxdb-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "45e0c9db8145a38bff94bf66477593bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3739,
            "upload_time": "2024-10-21T10:29:28",
            "upload_time_iso_8601": "2024-10-21T10:29:28.052207Z",
            "url": "https://files.pythonhosted.org/packages/33/5c/123cbc4461c1df50fa6882ea99daf666617e3d6842eb29f36db2e95f70f8/dm_aioinfluxdb-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 10:29:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MykhLibs",
    "github_project": "dm-aioinfluxdb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "dm-logger",
            "specs": [
                [
                    "~=",
                    "0.5.2"
                ]
            ]
        },
        {
            "name": "aiohttp",
            "specs": [
                [
                    ">=",
                    "3.9.2"
                ],
                [
                    "<",
                    "4.0.0"
                ]
            ]
        },
        {
            "name": "aiocsv",
            "specs": [
                [
                    ">=",
                    "1.2.5"
                ],
                [
                    "<",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "influxdb-client",
            "specs": [
                [
                    "~=",
                    "1.39.0"
                ]
            ]
        }
    ],
    "lcname": "dm-aioinfluxdb"
}
        
Elapsed time: 0.42308s