Skip to content

Commit 87f079c

Browse files
committed
docs: adds code documentation to key public methods
1 parent 0559be4 commit 87f079c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

influxdb_client_3/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,23 @@ def query(self, query: str, language: str = "sql", mode: str = "all", database:
279279
raise e
280280

281281
async def query_async(self, query: str, language: str = "sql", mode: str = "all", database: str = None, **kwargs):
282+
"""Query data from InfluxDB asynchronously.
283+
284+
If you want to use query parameters, you can pass them as kwargs:
285+
286+
>>> await client.query_async("select * from cpu where host=$host", query_parameters={"host": "server01"})
287+
288+
:param query: The query to execute on the database.
289+
:param language: The query language to use. It should be one of "influxql" or "sql". Defaults to "sql".
290+
:param mode: The mode to use for the query. It should be one of "all", "pandas", "polars", "chunk",
291+
"reader" or "schema". Defaults to "all".
292+
:param database: The database to query from. If not provided, uses the database provided during initialization.
293+
:param kwargs: Additional arguments to pass to the ``FlightCallOptions headers``. For example, it can be used to
294+
set up per request headers.
295+
:keyword query_parameters: The query parameters to use in the query.
296+
It should be a ``dictionary`` of key-value pairs.
297+
:return: The query result in the specified mode.
298+
"""
282299
if mode == "polars" and polars is False:
283300
raise ImportError("Polars is not installed. Please install it with `pip install polars`.")
284301

influxdb_client_3/query/query_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ def query(self, query: str, language: str, mode: str, database: str, **kwargs):
172172
raise e
173173

174174
async def query_async(self, query: str, language: str, mode: str, database: str, **kwargs):
175+
"""Query data from InfluxDB asynchronously.
176+
177+
Wraps internal FlightClient.doGet call in its own executor, so that the event_loop will not be blocked.
178+
179+
:param query: The query to execute on the database.
180+
:param language: The query language.
181+
:param mode: The mode to use for the query.
182+
It should be one of "all", "pandas", "polars", "chunk", "reader" or "schema".
183+
:param database: The database to query from.
184+
:param kwargs: Additional arguments to pass to the ``FlightCallOptions headers``.
185+
For example, it can be used to set up per request headers.
186+
:keyword query_parameters: The query parameters to use in the query.
187+
It should be a ``dictionary`` of key-value pairs.
188+
:return: The query result in the specified mode.
189+
"""
175190
try:
176191
ticket, options = self._prepare_query(query, language, database, **kwargs)
177192
loop = asyncio.get_running_loop()

tests/util/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88

99

1010
def asyncio_run(async_func):
11+
"""
12+
Fixture for running tests asynchronously
13+
14+
Example
15+
16+
.. sourcecode:: python
17+
18+
@asyncio_run
19+
async def test_my_feature(self):
20+
asyncio.sleep(1)
21+
print("waking...")
22+
...
23+
24+
:param async_func:
25+
:return:
26+
"""
1127
def wrapper(*args, **kwargs):
1228
try:
1329
return asyncio.run(async_func(*args, **kwargs))

0 commit comments

Comments
 (0)