# DM-aioinfluxdb
## Urls
* [PyPI](https://pypi.org/project/dm-aioinfluxdb)
* [GitHub](https://github.com/DIMKA4621/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/fb/60/ddd9874d576f9cc59bfd2bae1967c55b64508ed9d653f8809b2769a73461/dm_aioinfluxdb-0.2.5.tar.gz",
"platform": null,
"description": "# DM-aioinfluxdb\n\n## Urls\n\n* [PyPI](https://pypi.org/project/dm-aioinfluxdb)\n* [GitHub](https://github.com/DIMKA4621/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.5",
"project_urls": {
"GitHub": "https://github.com/DIMKA4621/dm-aioinfluxdb",
"Homepage": "https://pypi.org/project/dm-aioinfluxdb"
},
"split_keywords": [
"dm",
"aioinfluxdb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "22160c4b3e1a81ccce690d8ec149726dfc4d03f946d2b52ff9c482e7261c478d",
"md5": "4db57699e0d2d526c0f8ddab50541c40",
"sha256": "70fdc949d0a64e76e51559e106de18af92c1acd19952e69994f32e31e035468d"
},
"downloads": -1,
"filename": "dm_aioinfluxdb-0.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4db57699e0d2d526c0f8ddab50541c40",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4005,
"upload_time": "2024-04-15T11:45:17",
"upload_time_iso_8601": "2024-04-15T11:45:17.952643Z",
"url": "https://files.pythonhosted.org/packages/22/16/0c4b3e1a81ccce690d8ec149726dfc4d03f946d2b52ff9c482e7261c478d/dm_aioinfluxdb-0.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fb60ddd9874d576f9cc59bfd2bae1967c55b64508ed9d653f8809b2769a73461",
"md5": "b54871fc0852d0e712076efe96b65a4b",
"sha256": "73ef4aa094bcbae630d34d01887c4fe68c2fc8d8237550f3baebe912b8233685"
},
"downloads": -1,
"filename": "dm_aioinfluxdb-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "b54871fc0852d0e712076efe96b65a4b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 3703,
"upload_time": "2024-04-15T11:45:19",
"upload_time_iso_8601": "2024-04-15T11:45:19.444885Z",
"url": "https://files.pythonhosted.org/packages/fb/60/ddd9874d576f9cc59bfd2bae1967c55b64508ed9d653f8809b2769a73461/dm_aioinfluxdb-0.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-15 11:45:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "DIMKA4621",
"github_project": "dm-aioinfluxdb",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "aiohttp",
"specs": [
[
"==",
"3.9.2"
]
]
},
{
"name": "aiocsv",
"specs": [
[
"==",
"1.2.5"
]
]
},
{
"name": "dm-logger",
"specs": [
[
"==",
"0.5.2"
]
]
},
{
"name": "influxdb-client",
"specs": [
[
"==",
"1.39.0"
]
]
}
],
"lcname": "dm-aioinfluxdb"
}