Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4

Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Python connector for ThingsDB

> This library requires Python 3.9 or higher.
> This library requires Python 3.10 or higher.

---------------------------------------

Expand Down Expand Up @@ -89,8 +89,8 @@ ThingsDB.
```python
thingsdb.client.Client(
auto_reconnect: bool = True,
ssl: Optional[Union[bool, ssl.SSLContext]] = None,
loop: Optional[asyncio.AbstractEventLoop] = None
ssl: bool | ssl.SSLContext | None = None,
loop: asyncio.AbstractEventLoop | None = None
) -> Client
```
Initialize a ThingsDB client
Expand Down Expand Up @@ -119,8 +119,8 @@ Initialize a ThingsDB client

```python
async Client().authenticate(
*auth: Union[str, tuple],
timeout: Optional[int] = 5
*auth: str | tuple,
timeout: int | None = 5
) -> None
```

Expand Down Expand Up @@ -166,7 +166,7 @@ This is equivalent of combining [close()](#close)) and [wait_closed()](#wait_clo
Client().connect(
host: str,
port: int = 9200,
timeout: Optional[int] = 5
timeout: int | None = 5
) -> asyncio.Future
```

Expand Down Expand Up @@ -204,7 +204,7 @@ set to `None` when successful.
```python
Client().connect_pool(
pool: list,
*auth: Union[str, tuple]
*auth: str | tuple
) -> asyncio.Future
```

Expand Down Expand Up @@ -313,8 +313,8 @@ Can be used to check if the client is using a WebSocket connection.
```python
Client().query(
code: str,
scope: Optional[str] = None,
timeout: Optional[int] = None,
scope: str | None = None,
timeout: int | None = None,
skip_strip_code: bool = False,
**kwargs: Any
) -> asyncio.Future
Expand Down Expand Up @@ -368,7 +368,7 @@ contain the result of the ThingsDB code when successful.
### reconnect

```python
async Client().reconnect() -> Optional[Future]
async Client().reconnect() -> Future | None
```

Re-connect to ThingsDB.
Expand All @@ -384,9 +384,9 @@ possible but not required.
```python
Client().run(
procedure: str,
*args: Optional[Any],
scope: Optional[str] = None,
timeout: Optional[int] = None,
*args: Any,
scope: str | None = None,
timeout: int | None = None,
**kwargs: Any
) -> asyncio.Future
```
Expand Down Expand Up @@ -547,7 +547,7 @@ Property | Description
### join

```python
Room().join(client: Client, wait: Optional[float] = 60.0) -> None
Room().join(client: Client, wait: float | None = 60.0) -> None
```

Joins the room.
Expand All @@ -572,7 +572,7 @@ Leave the room. If the room is not found, a `LookupError` will be raised.
### emit

```python
Room().emit(event: str, *args: Optional[Any],) -> asyncio.Future
Room().emit(event: str, *args: Any) -> asyncio.Future
```

Emit an event to a room.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
],
install_requires=[
'msgpack',
Expand Down
44 changes: 21 additions & 23 deletions thingsdb/client/buildin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import asyncio
import datetime
from abc import ABC, abstractmethod
from typing import Union as U
from typing import Optional
from abc import abstractmethod
from typing import Any


Expand All @@ -15,13 +13,13 @@ class Buildin:
def query(
self,
code: str,
scope: Optional[str] = None,
timeout: Optional[int] = None,
scope: str | None = None,
timeout: int | None = None,
skip_strip_code: bool = False,
**kwargs: Any) -> asyncio.Future[Any]:
...

async def collection_info(self, collection: U[int, str]) -> dict:
async def collection_info(self, collection: int | str) -> dict:
"""Returns information about a specific collection.

This function requires QUERY privileges on the requested collection,
Expand All @@ -39,7 +37,7 @@ async def collections_info(self) -> list:
"""
return await self.query('collections_info()', scope='@t')

async def del_collection(self, collection: U[int, str]):
async def del_collection(self, collection: int | str):
"""Delete a collection.

This function generates a change.
Expand Down Expand Up @@ -104,7 +102,7 @@ async def del_user(self, name: str):
async def deploy_module(
self,
name: str,
data: Optional[U[bytes, str]] = None):
data: bytes | str | None = None):
"""Deploy a module on all nodes.

The module must be configured first, using the new_module() function.
Expand All @@ -127,7 +125,7 @@ async def deploy_module(
data=data,
scope='@t')

async def grant(self, target: U[int, str], user: str, mask: int):
async def grant(self, target: int | str, user: str, mask: int):
"""Grant, collection or general, privileges to a user.

Access to a user is provided by setting a bit mask to either the @node,
Expand Down Expand Up @@ -224,7 +222,7 @@ async def new_module(
self,
name: str,
source: str,
configuration: Optional[Any] = None):
configuration: Any = None):
"""Creates (and configures) a new module for ThingsDB.

This function generates a change."""
Expand All @@ -239,7 +237,7 @@ async def new_node(
self,
secret: str,
name: str,
port: Optional[int] = 9220) -> int:
port: int | None = 9220) -> int:
"""Adds a new node to ThingsDB.

This function generates a change."""
Expand All @@ -253,7 +251,7 @@ async def new_node(
async def new_token(
self,
user: str,
expiration_time: Optional[datetime.datetime] = None,
expiration_time: datetime.datetime | None = None,
description: str = ''):

ts = None if expiration_time is None \
Expand Down Expand Up @@ -285,7 +283,7 @@ async def refresh_module(self, name: str):

async def rename_collection(
self,
collection: U[int, str],
collection: int | str,
new_name: str) -> None:
return await self.query(
'rename_collection(collection, new_name)',
Expand All @@ -310,14 +308,14 @@ async def rename_user(self, name: str, new_name: str) -> None:
async def restore(
self,
filename: str,
options: Optional[dict] = {}):
options: dict[str, Any] | None = {}):
return await self.query(
'restore(filename, options)',
filename=filename,
options=options,
scope='@t')

async def revoke(self, target: U[int, str], user: str, mask: int):
async def revoke(self, target: int | str, user: str, mask: int):
return await self.query(
'revoke(target, user, mask)',
target=target,
Expand All @@ -328,7 +326,7 @@ async def revoke(self, target: U[int, str], user: str, mask: int):
async def set_module_conf(
self,
name: str,
configuration: Optional[dict] = None):
configuration: dict[str, Any] | None = None):
return await self.query(
'set_module_conf(name, configuration)',
name=name,
Expand All @@ -338,22 +336,22 @@ async def set_module_conf(
async def set_module_scope(
self,
name: str,
scope: U[str, None]):
scope: str | None):
return await self.query(
'set_module_scope(name, module_scope)',
name=name,
module_scope=scope,
scope='@t')

async def set_password(self, user: str,
new_password: Optional[str] = None) -> None:
new_password: str | None = None) -> None:
return await self.query(
'set_password(user, new_password)',
user=user,
new_password=new_password,
scope='@t')

async def set_time_zone(self, collection: U[int, str], zone: str):
async def set_time_zone(self, collection: int | str, zone: str):
"""By default each collection will be created with time zone UTC.

This function can be used to change the time zone for a collection. If
Expand All @@ -378,7 +376,7 @@ async def time_zones_info(self) -> list:
"""
return await self.query('time_zones_info()', scope='@t')

async def user_info(self, user: Optional[str] = None) -> dict:
async def user_info(self, user: str | None = None) -> dict:
if user is None:
return await self.query('user_info()', scope='@t')
return await self.query('user_info(user)', user=user, scope='@t')
Expand Down Expand Up @@ -419,9 +417,9 @@ async def has_backup(self, backup_id: int, scope='@n'):
async def new_backup(
self,
file_template: str,
start_ts: Optional[datetime.datetime] = None,
repeat: Optional[int] = 0,
max_files: Optional[int] = 7,
start_ts: datetime.datetime | None = None,
repeat: int | None = 0,
max_files: int | None = 7,
scope='@n'):

ts = None if start_ts is None else int(start_ts.timestamp())
Expand Down
Loading