arcadedb-python 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arcadedb_python/__init__.py +40 -0
- arcadedb_python/api/__init__.py +0 -0
- arcadedb_python/api/client.py +103 -0
- arcadedb_python/api/config.py +23 -0
- arcadedb_python/api/sync.py +112 -0
- arcadedb_python/dao/__init__.py +0 -0
- arcadedb_python/dao/database.py +321 -0
- arcadedb_python/model/__init__.py +0 -0
- arcadedb_python/model/database.py +7 -0
- arcadedb_python/model/request.py +16 -0
- arcadedb_python-0.2.0.dist-info/METADATA +344 -0
- arcadedb_python-0.2.0.dist-info/RECORD +14 -0
- arcadedb_python-0.2.0.dist-info/WHEEL +4 -0
- arcadedb_python-0.2.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""ArcadeDB Python Driver.
|
|
2
|
+
|
|
3
|
+
A Python driver for ArcadeDB - Multi-Model Database with Graph, Document,
|
|
4
|
+
Key-Value, Vector, and Time-Series support.
|
|
5
|
+
|
|
6
|
+
This package provides a comprehensive Python interface to ArcadeDB, enabling
|
|
7
|
+
developers to work with all of ArcadeDB's data models through a unified API.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
Basic usage:
|
|
11
|
+
|
|
12
|
+
>>> from arcadedb_python import DatabaseDao
|
|
13
|
+
>>> db = DatabaseDao("localhost", 2480, "mydb", "root", "password")
|
|
14
|
+
>>> result = db.query("sql", "SELECT FROM V LIMIT 10")
|
|
15
|
+
>>> print(result)
|
|
16
|
+
|
|
17
|
+
Classes:
|
|
18
|
+
DatabaseDao: Main database access object for executing queries
|
|
19
|
+
ArcadeDBConfig: Configuration class for connection settings
|
|
20
|
+
|
|
21
|
+
For more information, visit: https://docs.arcadedb.com/
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__version__ = "0.2.0"
|
|
25
|
+
__author__ = "Adams Rosales, ExtReMLapin, Steve Reiner"
|
|
26
|
+
__email__ = ""
|
|
27
|
+
__license__ = "Apache-2.0"
|
|
28
|
+
|
|
29
|
+
# Import main classes for easy access
|
|
30
|
+
from arcadedb_python.dao.database import DatabaseDao
|
|
31
|
+
from arcadedb_python.api.sync import SyncClient
|
|
32
|
+
from arcadedb_python.api.client import Client, LoginFailedException
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"DatabaseDao",
|
|
36
|
+
"SyncClient",
|
|
37
|
+
"Client",
|
|
38
|
+
"LoginFailedException",
|
|
39
|
+
"__version__",
|
|
40
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from . import config
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
from retry import retry
|
|
8
|
+
|
|
9
|
+
class LoginFailedException(Exception):
|
|
10
|
+
|
|
11
|
+
def __init__(self, javaErrorCode, message):
|
|
12
|
+
self.javaErrorCode = javaErrorCode
|
|
13
|
+
self.message = message
|
|
14
|
+
super().__init__(self.message)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Client(ABC):
|
|
18
|
+
def __init__(self, host: str, port: str, protocol: str = "http", **kwargs):
|
|
19
|
+
self.host = host
|
|
20
|
+
self.port = int(port)
|
|
21
|
+
self.kwargs = kwargs
|
|
22
|
+
self.protocol = protocol
|
|
23
|
+
self._validate()
|
|
24
|
+
|
|
25
|
+
def _validate(self):
|
|
26
|
+
if not self.host:
|
|
27
|
+
raise ValueError("Host is required")
|
|
28
|
+
if not self.port:
|
|
29
|
+
raise ValueError("Port is required")
|
|
30
|
+
endpoint_test = config.ARCADE_BASE_SERVER_ENDPOINT
|
|
31
|
+
try:
|
|
32
|
+
self.post(endpoint_test, { "command": "list databases" })
|
|
33
|
+
|
|
34
|
+
except LoginFailedException as e:
|
|
35
|
+
|
|
36
|
+
if e.javaErrorCode == "com.arcadedb.server.security.ServerSecurityException":
|
|
37
|
+
raise ValueError("Invalid credentials")
|
|
38
|
+
else:
|
|
39
|
+
raise ValueError("Unable to connect to server : ", e)
|
|
40
|
+
except Exception as e:
|
|
41
|
+
raise ValueError("Unable to connect to server : ", e)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _get_endpoint(self, endpoint: str) -> str:
|
|
47
|
+
if endpoint.startswith("/"):
|
|
48
|
+
endpoint = endpoint[1:]
|
|
49
|
+
if self.url.endswith("/"):
|
|
50
|
+
return f"{self.url}{endpoint}"
|
|
51
|
+
else:
|
|
52
|
+
return f"{self.url}/{endpoint}"
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def headers(self):
|
|
56
|
+
default = "application/json"
|
|
57
|
+
key = "content_type"
|
|
58
|
+
if key not in self.kwargs:
|
|
59
|
+
logging.warning(f"No content type, defaulting to {default}")
|
|
60
|
+
content_type = self.kwargs.get(key, default)
|
|
61
|
+
return {"Content-Type": content_type}
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def url(self) -> str:
|
|
65
|
+
return f"{self.protocol}://{self.host}:{self.port}"
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def username(self) -> str:
|
|
69
|
+
return self.kwargs.get("username") or self.kwargs.get("user")
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def password(self) -> str:
|
|
73
|
+
return self.kwargs.get("password") or self.kwargs.get("pw")
|
|
74
|
+
|
|
75
|
+
def __repr__(self) -> str:
|
|
76
|
+
return f"<host={self.host} port={self.port} user={self.username}>"
|
|
77
|
+
|
|
78
|
+
def __str__(self) -> str:
|
|
79
|
+
return self.__repr__()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@abstractmethod
|
|
86
|
+
@retry(
|
|
87
|
+
tries=config.API_RETRY_MAX,
|
|
88
|
+
delay=config.API_RETRY_DELAY,
|
|
89
|
+
backoff=config.API_RETRY_BACKOFF,
|
|
90
|
+
)
|
|
91
|
+
def post(self, endpoint: str, payload: dict, return_headers: bool=False, extra_headers: dict = {}) -> requests.Response:
|
|
92
|
+
pass
|
|
93
|
+
|
|
94
|
+
@abstractmethod
|
|
95
|
+
@retry(
|
|
96
|
+
tries=config.API_RETRY_MAX,
|
|
97
|
+
delay=config.API_RETRY_DELAY,
|
|
98
|
+
backoff=config.API_RETRY_BACKOFF,
|
|
99
|
+
)
|
|
100
|
+
def get(self, endpoint: str, return_headers: bool=False, extra_headers: dict = {}) -> requests.Response:
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _get_env_variable(key: str, default: str = None) -> str:
|
|
5
|
+
return os.environ.get(key, os.getenv(key, default))
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
ARCADE_BASE_ENDPOINT = _get_env_variable("ARCADE_API_ENDPOINT", "/api/v1")
|
|
9
|
+
ARCADE_BASE_SERVER_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/server"
|
|
10
|
+
ARCADE_BASE_EXISTS_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/exists"
|
|
11
|
+
ARCADE_BASE_COMMAND_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/command"
|
|
12
|
+
ARCADE_BASE_LIST_DB_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/databases"
|
|
13
|
+
ARCADE_BASE_QUERY_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/query"
|
|
14
|
+
|
|
15
|
+
ARCADE_BASE_TRANSACTION_BEGIN_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/begin"
|
|
16
|
+
ARCADE_BASE_TRANSACTION_COMMIT_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/commit"
|
|
17
|
+
ARCADE_BASE_TRANSACTION_ROLLBACK_ENDPOINT = f"{ARCADE_BASE_ENDPOINT}/rollback"
|
|
18
|
+
|
|
19
|
+
AVAILABLE_LANGUAGES = {"sql", "sqlscript", "graphql", "cypher", "gremlin", "mongo"}
|
|
20
|
+
|
|
21
|
+
API_RETRY_MAX = int(_get_env_variable("ARCADE_API_RETRY_MAX", "3"))
|
|
22
|
+
API_RETRY_DELAY = int(_get_env_variable("ARCADE_API_RETRY_DELAY", "1"))
|
|
23
|
+
API_RETRY_BACKOFF = int(_get_env_variable("ARCADE_API_RETRY_BACKOFF", "2"))
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from .client import Client, LoginFailedException
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import logging
|
|
5
|
+
import requests
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _filter_payload_for_log(payload: dict, max_chars: int = 500) -> dict:
|
|
10
|
+
"""Filter payload for logging by truncating embedding data to avoid cluttering logs.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
payload: The payload dictionary to filter
|
|
14
|
+
max_chars: Maximum characters to show for the entire payload
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
Filtered payload dictionary with embedding data truncated
|
|
18
|
+
"""
|
|
19
|
+
if not isinstance(payload, dict):
|
|
20
|
+
return payload
|
|
21
|
+
|
|
22
|
+
# Create a copy to avoid modifying the original
|
|
23
|
+
filtered_payload = payload.copy()
|
|
24
|
+
|
|
25
|
+
# Filter the 'command' field if it contains embedding arrays
|
|
26
|
+
if 'command' in filtered_payload and isinstance(filtered_payload['command'], str):
|
|
27
|
+
command = filtered_payload['command']
|
|
28
|
+
|
|
29
|
+
# Pattern to match embedding arrays like [0.123, -0.456, 0.789, ...]
|
|
30
|
+
embedding_pattern = r'\[[-0-9.,\s]+\]'
|
|
31
|
+
|
|
32
|
+
def replace_embedding(match):
|
|
33
|
+
full_embedding = match.group(0)
|
|
34
|
+
if len(full_embedding) > 50: # If embedding is long, truncate it
|
|
35
|
+
# Extract first few values to show dimension info
|
|
36
|
+
values = re.findall(r'[-0-9.]+', full_embedding[:100])
|
|
37
|
+
total_values = len(re.findall(r'[-0-9.]+', full_embedding))
|
|
38
|
+
if len(values) >= 2:
|
|
39
|
+
return f"[{values[0]}, {values[1]}, ...] (dim:{total_values})"
|
|
40
|
+
else:
|
|
41
|
+
return f"[...] (dim:{total_values})"
|
|
42
|
+
return full_embedding
|
|
43
|
+
|
|
44
|
+
# Replace embedding arrays with truncated versions
|
|
45
|
+
filtered_command = re.sub(embedding_pattern, replace_embedding, command)
|
|
46
|
+
|
|
47
|
+
# Limit total command length
|
|
48
|
+
if len(filtered_command) > max_chars:
|
|
49
|
+
filtered_command = filtered_command[:max_chars] + "..."
|
|
50
|
+
|
|
51
|
+
filtered_payload['command'] = filtered_command
|
|
52
|
+
|
|
53
|
+
return filtered_payload
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class SyncClient(Client):
|
|
57
|
+
def __init__(self, host: str, port: str, protocol: str = "http", **kwargs):
|
|
58
|
+
super().__init__(host, port, protocol, **kwargs)
|
|
59
|
+
|
|
60
|
+
def subhandler(self, response: requests.Response, return_headers: bool=False):
|
|
61
|
+
if response.status_code >= 400 :
|
|
62
|
+
json_decoded_data = response.json()
|
|
63
|
+
print(json_decoded_data)
|
|
64
|
+
java_error_code = json_decoded_data['exception'] if 'exception' in json_decoded_data else "Unknown error"
|
|
65
|
+
detail_error_code = None
|
|
66
|
+
if 'detail' in json_decoded_data:
|
|
67
|
+
detail_error_code = json_decoded_data['detail']
|
|
68
|
+
elif 'exception' in json_decoded_data:
|
|
69
|
+
detail_error_code = json_decoded_data['exception']
|
|
70
|
+
else:
|
|
71
|
+
detail_error_code = "Unknown error"
|
|
72
|
+
|
|
73
|
+
if java_error_code == "com.arcadedb.server.security.ServerSecurityException":
|
|
74
|
+
raise LoginFailedException(java_error_code, detail_error_code)
|
|
75
|
+
else:
|
|
76
|
+
raise Exception(java_error_code, detail_error_code)
|
|
77
|
+
|
|
78
|
+
response.raise_for_status()
|
|
79
|
+
logging.debug(f"response: {response.text}")
|
|
80
|
+
if return_headers is False:
|
|
81
|
+
if len(response.text) > 0:
|
|
82
|
+
try:
|
|
83
|
+
return response.json()["result"]
|
|
84
|
+
except:
|
|
85
|
+
return response.text
|
|
86
|
+
else:
|
|
87
|
+
return
|
|
88
|
+
else:
|
|
89
|
+
return response.headers
|
|
90
|
+
|
|
91
|
+
def post(self, endpoint: str, payload: dict, return_headers: bool=False, extra_headers: dict = {}) -> requests.Response:
|
|
92
|
+
endpoint = self._get_endpoint(endpoint)
|
|
93
|
+
filtered_payload = _filter_payload_for_log(payload)
|
|
94
|
+
logging.info(f"posting to {endpoint} with payload {filtered_payload}")
|
|
95
|
+
response = requests.post(
|
|
96
|
+
endpoint,
|
|
97
|
+
data=json.dumps(payload),
|
|
98
|
+
headers={**self.headers,**extra_headers},
|
|
99
|
+
auth=(self.username, self.password),
|
|
100
|
+
)
|
|
101
|
+
return self.subhandler(response, return_headers=return_headers)
|
|
102
|
+
|
|
103
|
+
def get(self, endpoint: str, return_headers: bool=False, extra_headers: dict = {}) -> requests.Response:
|
|
104
|
+
endpoint = self._get_endpoint(endpoint)
|
|
105
|
+
logging.info(f"submitting get request to {endpoint}")
|
|
106
|
+
response = requests.get(
|
|
107
|
+
endpoint,
|
|
108
|
+
auth=(self.username, self.password),
|
|
109
|
+
headers=extra_headers,
|
|
110
|
+
)
|
|
111
|
+
return self.subhandler(response, return_headers=return_headers)
|
|
112
|
+
|
|
File without changes
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
|
|
2
|
+
from ..api.client import Client
|
|
3
|
+
from ..api import config
|
|
4
|
+
from typing import Optional, Any, List, Union
|
|
5
|
+
from enum import Enum
|
|
6
|
+
import re
|
|
7
|
+
try:
|
|
8
|
+
import psycopg
|
|
9
|
+
PSYCOPG_AVAILABLE = True
|
|
10
|
+
except ImportError:
|
|
11
|
+
PSYCOPG_AVAILABLE = False
|
|
12
|
+
psycopg = None
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
from pygments.lexers import get_lexer_by_name
|
|
16
|
+
from pygments.token import string_to_tokentype
|
|
17
|
+
try:
|
|
18
|
+
# Try to get the Cypher lexer - might not be available
|
|
19
|
+
cypher_lexer = get_lexer_by_name("cypher")
|
|
20
|
+
except:
|
|
21
|
+
try:
|
|
22
|
+
# Fallback to SQL lexer
|
|
23
|
+
cypher_lexer = get_lexer_by_name("sql")
|
|
24
|
+
except:
|
|
25
|
+
cypher_lexer = None
|
|
26
|
+
|
|
27
|
+
if cypher_lexer:
|
|
28
|
+
punctuation = string_to_tokentype("Token.Punctuation")
|
|
29
|
+
global_var = string_to_tokentype("Token.Name.Variable.Global")
|
|
30
|
+
string_liral = string_to_tokentype("Token.Literal.String")
|
|
31
|
+
PYGMENTS_AVAILABLE = True
|
|
32
|
+
else:
|
|
33
|
+
PYGMENTS_AVAILABLE = False
|
|
34
|
+
except ImportError:
|
|
35
|
+
PYGMENTS_AVAILABLE = False
|
|
36
|
+
cypher_lexer = None
|
|
37
|
+
|
|
38
|
+
# Removed - now handled in the import section above
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DatabaseDao:
|
|
42
|
+
"""
|
|
43
|
+
Class to work with ArcadeDB databases
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
class IsolationLevel(Enum):
|
|
47
|
+
"""Isolation levels for transactions"""
|
|
48
|
+
READ_COMMITTED = "READ_COMMITTED"
|
|
49
|
+
REPEATABLE_READ = "REPEATABLE_READ"
|
|
50
|
+
|
|
51
|
+
class Driver(Enum):
|
|
52
|
+
HTTP="HTTP"
|
|
53
|
+
PSYCOPG="PSYCOPG"
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def exists(client, name: str) -> bool:
|
|
57
|
+
"""
|
|
58
|
+
Check if a database exists.
|
|
59
|
+
|
|
60
|
+
Parameters:
|
|
61
|
+
- client (Client): The ArcadeDB client.
|
|
62
|
+
- name (str): The name of the database.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
bool: True if the database exists, False otherwise.
|
|
66
|
+
"""
|
|
67
|
+
response = client.get(f"{config.ARCADE_BASE_EXISTS_ENDPOINT}/{name}")
|
|
68
|
+
return response
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def create(client: Client, name: str) -> 'DatabaseDao':
|
|
72
|
+
"""
|
|
73
|
+
Create a new database.
|
|
74
|
+
|
|
75
|
+
Parameters:
|
|
76
|
+
- client (Client): The ArcadeDB client.
|
|
77
|
+
- name (str): The name of the new database.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
DatabaseDao: An instance of DatabaseDao for the created database.
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
- ValueError: If the database already exists.
|
|
84
|
+
- ValueError: If the creation of the database fails.
|
|
85
|
+
"""
|
|
86
|
+
if DatabaseDao.exists(client, name):
|
|
87
|
+
raise ValueError(f"Database {name} already exists")
|
|
88
|
+
|
|
89
|
+
ret = client.post(config.ARCADE_BASE_SERVER_ENDPOINT, {"command": f"create database {name}"})
|
|
90
|
+
if ret == "ok":
|
|
91
|
+
return DatabaseDao(client, name)
|
|
92
|
+
else:
|
|
93
|
+
raise ValueError(f"Could not create database {name}: {ret}")
|
|
94
|
+
|
|
95
|
+
@staticmethod
|
|
96
|
+
def delete(client: Client, name: str) -> bool:
|
|
97
|
+
"""
|
|
98
|
+
Delete a database.
|
|
99
|
+
|
|
100
|
+
Parameters:
|
|
101
|
+
- client (Client): The ArcadeDB client.
|
|
102
|
+
- name (str): The name of the database to be deleted.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
bool: True if the database is successfully deleted.
|
|
106
|
+
|
|
107
|
+
Raises:
|
|
108
|
+
- ValueError: If the database does not exist.
|
|
109
|
+
- ValueError: If the deletion of the database fails.
|
|
110
|
+
"""
|
|
111
|
+
if not DatabaseDao.exists(client, name):
|
|
112
|
+
raise ValueError(f"Database {name} does not exist")
|
|
113
|
+
ret = client.post(config.ARCADE_BASE_SERVER_ENDPOINT, {"command": f"drop database {name}"})
|
|
114
|
+
if ret == "ok":
|
|
115
|
+
return True
|
|
116
|
+
else:
|
|
117
|
+
raise ValueError(f"Could not drop database {name}: {ret}")
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def list_databases(client: Client) -> List:
|
|
121
|
+
"""
|
|
122
|
+
List all databases.
|
|
123
|
+
|
|
124
|
+
Parameters:
|
|
125
|
+
- client (Client): The ArcadeDB client.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
str: The list of databases.
|
|
129
|
+
"""
|
|
130
|
+
return client.get(config.ARCADE_BASE_LIST_DB_ENDPOINT)
|
|
131
|
+
|
|
132
|
+
def __init__(
|
|
133
|
+
self,
|
|
134
|
+
client: Client,
|
|
135
|
+
database_name: str,
|
|
136
|
+
driver:Driver=Driver.HTTP
|
|
137
|
+
|
|
138
|
+
):
|
|
139
|
+
"""
|
|
140
|
+
Initialize a DatabaseDao instance.
|
|
141
|
+
|
|
142
|
+
Parameters:
|
|
143
|
+
- client (Client): The ArcadeDB client.
|
|
144
|
+
- database_name (str): The name of the database.
|
|
145
|
+
|
|
146
|
+
Raises:
|
|
147
|
+
- ValueError: If the database does not exist. Call create() to create a new database.
|
|
148
|
+
"""
|
|
149
|
+
self.client = client
|
|
150
|
+
self.database_name = database_name
|
|
151
|
+
self.driver = driver
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
if self.driver == self.Driver.PSYCOPG:
|
|
155
|
+
if not PSYCOPG_AVAILABLE:
|
|
156
|
+
raise ImportError("psycopg is required for PSYCOPG driver. Install with: pip install psycopg")
|
|
157
|
+
port = self.client.port
|
|
158
|
+
if client.port == 2480:
|
|
159
|
+
print("Auto switching port to 5432 as we're using PSYCOPG driver")
|
|
160
|
+
port = 5432
|
|
161
|
+
self.connection = psycopg.connect(user=self.client.username, password=self.client.password,
|
|
162
|
+
host=self.client.host,
|
|
163
|
+
port=port,
|
|
164
|
+
dbname=self.database_name,
|
|
165
|
+
sslmode='disable'
|
|
166
|
+
)
|
|
167
|
+
else:
|
|
168
|
+
self.connection = None
|
|
169
|
+
if not DatabaseDao.exists(client, database_name):
|
|
170
|
+
raise ValueError(f"Database {database_name} does not exist, call create()")
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
cypher_var_regex = re.compile(r'\$([a-zA-Z_][a-zA-Z0-9_]*)')
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@staticmethod
|
|
177
|
+
def cypher_formater(query: str, params: dict) -> str:
|
|
178
|
+
if not PYGMENTS_AVAILABLE:
|
|
179
|
+
# Fallback to simple parameter substitution if pygments not available
|
|
180
|
+
import re
|
|
181
|
+
def replace_param(match):
|
|
182
|
+
param_name = match.group(1)
|
|
183
|
+
if param_name in params:
|
|
184
|
+
value = params[param_name]
|
|
185
|
+
if isinstance(value, str):
|
|
186
|
+
return f"'{value.replace('\\', '\\\\').replace('\'', '\\\'')}'"
|
|
187
|
+
return str(value)
|
|
188
|
+
return match.group(0)
|
|
189
|
+
|
|
190
|
+
result = re.sub(r'\$([a-zA-Z_][a-zA-Z0-9_]*)', replace_param, query)
|
|
191
|
+
return result, {}
|
|
192
|
+
|
|
193
|
+
skipped_params = {}
|
|
194
|
+
tokens = list(cypher_lexer.get_tokens(query))
|
|
195
|
+
i = 0
|
|
196
|
+
len_tokens = len(tokens)
|
|
197
|
+
while i < len_tokens-1:
|
|
198
|
+
if tokens[i][0] == punctuation and tokens[i+1][0] == global_var:
|
|
199
|
+
var_name = tokens[i+1][1]
|
|
200
|
+
assert var_name in params, f"Variable {var_name} not found in the parameters"
|
|
201
|
+
if isinstance(params[var_name], str) and '$' in params[var_name]:
|
|
202
|
+
skipped_params[var_name] = params[var_name]
|
|
203
|
+
i += 2
|
|
204
|
+
continue
|
|
205
|
+
if isinstance(params[var_name], list):
|
|
206
|
+
skipped_params[var_name] = params[var_name]
|
|
207
|
+
i += 2
|
|
208
|
+
continue
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
escaped_string = str(params[var_name]).replace('\\', '\\\\').replace('\'', '\\\'')
|
|
212
|
+
tokens[i] = (string_liral, f"'{escaped_string}'")
|
|
213
|
+
tokens.pop(i+1)
|
|
214
|
+
len_tokens -= 1
|
|
215
|
+
|
|
216
|
+
i += 1
|
|
217
|
+
return "".join([x[1] for x in tokens]), skipped_params
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def query(
|
|
222
|
+
self,
|
|
223
|
+
language: str,
|
|
224
|
+
command: str,
|
|
225
|
+
limit: Optional[int] = None,
|
|
226
|
+
params: Optional[Any] = None,
|
|
227
|
+
serializer: Optional[str] = None,
|
|
228
|
+
session_id: Optional[str] = None,
|
|
229
|
+
is_command: Optional[bool] = False
|
|
230
|
+
) -> Union[str, List, dict]:
|
|
231
|
+
"""
|
|
232
|
+
Execute a query on the database.
|
|
233
|
+
|
|
234
|
+
Parameters:
|
|
235
|
+
- language (str): The query language.
|
|
236
|
+
- command (str): The query command.
|
|
237
|
+
- limit (int): The limit on the number of results (optional).
|
|
238
|
+
- params: The parameters for the query (optional).
|
|
239
|
+
- serializer (str): The serializer for the query results (optional).
|
|
240
|
+
- session_id: The session ID for the query (optional).
|
|
241
|
+
- is_command: If the query is a command (optional), you need this to run non-idempotent commands.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
str: The result of the query.
|
|
245
|
+
"""
|
|
246
|
+
language = language.lower()
|
|
247
|
+
if language not in config.AVAILABLE_LANGUAGES:
|
|
248
|
+
raise ValueError(f"Language {language} not supported")
|
|
249
|
+
if limit is not None:
|
|
250
|
+
assert isinstance(limit, int), "Limit must be an integer"
|
|
251
|
+
serializer = serializer.lower() if serializer else serializer
|
|
252
|
+
assert serializer in {None, "graph", "record"}, "Serializer must be None, 'graph' or 'record'"
|
|
253
|
+
|
|
254
|
+
if language == "cypher" and params:
|
|
255
|
+
command, new_params = self.cypher_formater(command, params)
|
|
256
|
+
params = new_params if len(new_params) > 0 else None
|
|
257
|
+
payload = {
|
|
258
|
+
"command": command,
|
|
259
|
+
"language": language,
|
|
260
|
+
}
|
|
261
|
+
if limit is not None:
|
|
262
|
+
payload["limit"] = limit
|
|
263
|
+
if params is not None:
|
|
264
|
+
payload["params"] = params
|
|
265
|
+
if serializer is not None:
|
|
266
|
+
assert self.driver == self.Driver.HTTP, "Serializer is only support with HTTP driver"
|
|
267
|
+
payload["serializer"] = serializer
|
|
268
|
+
extra_headers = {}
|
|
269
|
+
if session_id is not None:
|
|
270
|
+
assert self.driver == self.Driver.HTTP, "Session ID is only support with HTTP driver"
|
|
271
|
+
extra_headers["arcadedb-session-id"] = session_id
|
|
272
|
+
if self.driver == self.Driver.HTTP:
|
|
273
|
+
req = self.client.post(f"{config.ARCADE_BASE_QUERY_ENDPOINT if is_command is False else config.ARCADE_BASE_COMMAND_ENDPOINT}/{self.database_name}", payload, extra_headers=extra_headers)
|
|
274
|
+
else:
|
|
275
|
+
with self.connection.cursor(row_factory=psycopg.rows.dict_row) as cursor:
|
|
276
|
+
prefix = "" if language == "sql" else f"{{{language}}}"
|
|
277
|
+
cursor.execute(query=prefix+command, params=params)
|
|
278
|
+
return cursor.fetchall()
|
|
279
|
+
|
|
280
|
+
return req
|
|
281
|
+
|
|
282
|
+
def begin_transaction(self, isolation_level: IsolationLevel = IsolationLevel.READ_COMMITTED) -> str:
|
|
283
|
+
|
|
284
|
+
"""
|
|
285
|
+
Begin a new transaction.
|
|
286
|
+
|
|
287
|
+
Parameters:
|
|
288
|
+
- isolation_level (IsolationLevel): The isolation level for the transaction (default: READ_COMMITTED).
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
str: The session ID for the new transaction.
|
|
292
|
+
"""
|
|
293
|
+
headers = self.client.post(f"{config.ARCADE_BASE_TRANSACTION_BEGIN_ENDPOINT}/{self.database_name}", {"isolationLevel": isolation_level.value}, return_headers=True)
|
|
294
|
+
return headers["arcadedb-session-id"]
|
|
295
|
+
|
|
296
|
+
def commit_transaction(self, session_id) -> None:
|
|
297
|
+
"""
|
|
298
|
+
Commit a transaction.
|
|
299
|
+
|
|
300
|
+
Parameters:
|
|
301
|
+
- session_id: The session ID of the transaction to be committed.
|
|
302
|
+
"""
|
|
303
|
+
self.client.post(f"{config.ARCADE_BASE_TRANSACTION_COMMIT_ENDPOINT}/{self.database_name}", {}, extra_headers={"arcadedb-session-id": session_id})
|
|
304
|
+
|
|
305
|
+
def rollback_transaction(self, session_id) -> None:
|
|
306
|
+
"""
|
|
307
|
+
Rollback a transaction.
|
|
308
|
+
|
|
309
|
+
Parameters:
|
|
310
|
+
- session_id: The session ID of the transaction to be rolled back.
|
|
311
|
+
"""
|
|
312
|
+
self.client.post(f"{config.ARCADE_BASE_TRANSACTION_ROLLBACK_ENDPOINT}/{self.database_name}", {}, extra_headers={"arcadedb-session-id": session_id})
|
|
313
|
+
|
|
314
|
+
def __repr__(self) -> str:
|
|
315
|
+
"""
|
|
316
|
+
Return a string representation of the DatabaseDao instance.
|
|
317
|
+
|
|
318
|
+
Returns:
|
|
319
|
+
str: A string representation of the form "<DatabaseDao database_name={self.database_name}> @ {self.client}".
|
|
320
|
+
"""
|
|
321
|
+
return f"<DatabaseDao database_name={self.database_name}> @ {self.client}"
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from typing import Union
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class RequestData:
|
|
8
|
+
endpoint: str
|
|
9
|
+
command: Union[str, None] = None
|
|
10
|
+
language: Union[str, None] = "sql"
|
|
11
|
+
|
|
12
|
+
def payload(self) -> dict:
|
|
13
|
+
if not self.language:
|
|
14
|
+
return {"command": self.command}
|
|
15
|
+
else:
|
|
16
|
+
return {"command": self.command, "language": self.language}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arcadedb-python
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python driver for ArcadeDB - Multi-Model Database with Graph, Document, Key-Value, Vector, and Time-Series support
|
|
5
|
+
Project-URL: Homepage, https://github.com/stevereiner/arcadedb-python
|
|
6
|
+
Project-URL: Documentation, https://docs.arcadedb.com/
|
|
7
|
+
Project-URL: Repository, https://github.com/stevereiner/arcadedb-python
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/stevereiner/arcadedb-python/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/stevereiner/arcadedb-python/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Adams Rosales, ExtReMLapin, Steve Reiner
|
|
11
|
+
Maintainer: Steve Reiner
|
|
12
|
+
License-Expression: Apache-2.0
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: arcadedb,database,document,graph,key-value,multi-model,nosql,python-driver,time-series,vector
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Database
|
|
25
|
+
Classifier: Topic :: Database :: Database Engines/Servers
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: requests>=2.25.0
|
|
30
|
+
Requires-Dist: retry>=0.9.2
|
|
31
|
+
Provides-Extra: cypher
|
|
32
|
+
Requires-Dist: pygments>=2.0.0; extra == 'cypher'
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: flake8>=6.0.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
|
|
41
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
42
|
+
Requires-Dist: tox>=4.0.0; extra == 'dev'
|
|
43
|
+
Provides-Extra: full
|
|
44
|
+
Requires-Dist: psycopg>=3.0.0; extra == 'full'
|
|
45
|
+
Requires-Dist: pygments>=2.0.0; extra == 'full'
|
|
46
|
+
Provides-Extra: postgresql
|
|
47
|
+
Requires-Dist: psycopg>=3.0.0; extra == 'postgresql'
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# ArcadeDB Python Driver
|
|
51
|
+
|
|
52
|
+
[](https://badge.fury.io/py/arcadedb-python)
|
|
53
|
+
[](https://pypi.org/project/arcadedb-python/)
|
|
54
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
55
|
+
|
|
56
|
+
A comprehensive Python driver for [ArcadeDB](https://arcadedb.com) - the Multi-Model Database that supports Graph, Document, Key-Value, Vector, and Time-Series models in a single engine.
|
|
57
|
+
|
|
58
|
+
## Credits & Attribution
|
|
59
|
+
|
|
60
|
+
This driver builds upon the excellent work of the original ArcadeDB Python driver contributors:
|
|
61
|
+
|
|
62
|
+
- **Adams Rosales** ([@adaros92](https://github.com/adaros92)) - Original [arcadedb-python-driver](https://github.com/adaros92/arcadedb-python-driver)
|
|
63
|
+
- **ExtReMLapin** ([@ExtReMLapin](https://github.com/ExtReMLapin)) - Core contributor and enhancements
|
|
64
|
+
- **ArcadeDB Team** - The amazing [ArcadeDB](https://github.com/ArcadeData/arcadedb) database engine
|
|
65
|
+
|
|
66
|
+
This modernized version enhances the original work with updated packaging, comprehensive documentation, and production-ready features while maintaining full compatibility with the [ArcadeDB](https://arcadedb.com/) database.
|
|
67
|
+
|
|
68
|
+
## Features
|
|
69
|
+
|
|
70
|
+
- **Multi-Model Support**: Work with Graph, Document, Key-Value, Vector, and Time-Series data models
|
|
71
|
+
- **High Performance**: Optimized for speed with native ArcadeDB protocols
|
|
72
|
+
- **Full API Coverage**: Complete access to ArcadeDB's REST API and SQL capabilities
|
|
73
|
+
- **Type Safety**: Comprehensive type hints for better development experience
|
|
74
|
+
- **Async Support**: Both synchronous and asynchronous operation modes
|
|
75
|
+
- **Connection Pooling**: Efficient connection management for production use
|
|
76
|
+
- **Comprehensive Testing**: Extensive test suite ensuring reliability
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
### Using UV (Recommended)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Install uv if not already installed
|
|
84
|
+
pip install uv
|
|
85
|
+
|
|
86
|
+
# Create virtual environment and install
|
|
87
|
+
uv venv
|
|
88
|
+
uv pip install arcadedb-python
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Using Pip
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install arcadedb-python
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Optional Dependencies
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# PostgreSQL driver support
|
|
101
|
+
uv pip install arcadedb-python[postgresql]
|
|
102
|
+
# or: pip install arcadedb-python[postgresql]
|
|
103
|
+
|
|
104
|
+
# Cypher syntax highlighting
|
|
105
|
+
uv pip install arcadedb-python[cypher]
|
|
106
|
+
# or: pip install arcadedb-python[cypher]
|
|
107
|
+
|
|
108
|
+
# All optional features
|
|
109
|
+
uv pip install arcadedb-python[full]
|
|
110
|
+
# or: pip install arcadedb-python[full]
|
|
111
|
+
|
|
112
|
+
# Development dependencies
|
|
113
|
+
uv pip install arcadedb-python[dev]
|
|
114
|
+
# or: pip install arcadedb-python[dev]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Quick Start
|
|
118
|
+
|
|
119
|
+
### Basic Usage
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from arcadedb_python import DatabaseDao
|
|
123
|
+
|
|
124
|
+
# Connect to ArcadeDB
|
|
125
|
+
db = DatabaseDao(
|
|
126
|
+
host="localhost",
|
|
127
|
+
port=2480,
|
|
128
|
+
database="mydb",
|
|
129
|
+
username="root",
|
|
130
|
+
password="playwithdata"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Execute SQL queries
|
|
134
|
+
result = db.query("sql", "SELECT FROM V LIMIT 10")
|
|
135
|
+
print(result)
|
|
136
|
+
|
|
137
|
+
# Create vertices and edges
|
|
138
|
+
db.command("sql", "CREATE VERTEX TYPE Person")
|
|
139
|
+
db.command("sql", "INSERT INTO Person SET name = 'John', age = 30")
|
|
140
|
+
|
|
141
|
+
# Graph traversal
|
|
142
|
+
result = db.query("sql", """
|
|
143
|
+
MATCH {type: Person, as: person}
|
|
144
|
+
RETURN person.name, person.age
|
|
145
|
+
""")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Configuration
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from arcadedb_python import ArcadeDBConfig, DatabaseDao
|
|
152
|
+
|
|
153
|
+
# Using configuration object
|
|
154
|
+
config = ArcadeDBConfig(
|
|
155
|
+
host="localhost",
|
|
156
|
+
port=2480,
|
|
157
|
+
username="root",
|
|
158
|
+
password="playwithdata"
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
db = DatabaseDao.from_config(config, "mydb")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Async Operations
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
import asyncio
|
|
168
|
+
from arcadedb_python import DatabaseDao
|
|
169
|
+
|
|
170
|
+
async def main():
|
|
171
|
+
db = DatabaseDao("localhost", 2480, "mydb", "root", "playwithdata")
|
|
172
|
+
|
|
173
|
+
# Async query execution
|
|
174
|
+
result = await db.query_async("sql", "SELECT FROM V LIMIT 10")
|
|
175
|
+
print(result)
|
|
176
|
+
|
|
177
|
+
asyncio.run(main())
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Advanced Usage
|
|
181
|
+
|
|
182
|
+
### Working with Different Data Models
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
# Document operations
|
|
186
|
+
db.command("sql", "CREATE DOCUMENT TYPE Product")
|
|
187
|
+
db.command("sql", """
|
|
188
|
+
INSERT INTO Product CONTENT {
|
|
189
|
+
"name": "Laptop",
|
|
190
|
+
"price": 999.99,
|
|
191
|
+
"specs": {
|
|
192
|
+
"cpu": "Intel i7",
|
|
193
|
+
"ram": "16GB"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
""")
|
|
197
|
+
|
|
198
|
+
# Graph operations
|
|
199
|
+
db.command("sql", "CREATE VERTEX TYPE Customer")
|
|
200
|
+
db.command("sql", "CREATE EDGE TYPE Purchased")
|
|
201
|
+
db.command("sql", """
|
|
202
|
+
CREATE EDGE Purchased
|
|
203
|
+
FROM (SELECT FROM Customer WHERE name = 'John')
|
|
204
|
+
TO (SELECT FROM Product WHERE name = 'Laptop')
|
|
205
|
+
SET date = date(), amount = 999.99
|
|
206
|
+
""")
|
|
207
|
+
|
|
208
|
+
# Key-Value operations
|
|
209
|
+
db.command("sql", "CREATE DOCUMENT TYPE Settings")
|
|
210
|
+
db.command("sql", "INSERT INTO Settings SET key = 'theme', value = 'dark'")
|
|
211
|
+
|
|
212
|
+
# Time-Series operations
|
|
213
|
+
db.command("sql", "CREATE VERTEX TYPE Sensor")
|
|
214
|
+
db.command("sql", """
|
|
215
|
+
INSERT INTO Sensor SET
|
|
216
|
+
sensor_id = 'temp_01',
|
|
217
|
+
timestamp = sysdate(),
|
|
218
|
+
temperature = 23.5
|
|
219
|
+
""")
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Vector Search (for AI/ML applications)
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
# Store embeddings
|
|
226
|
+
db.command("sql", """
|
|
227
|
+
CREATE VERTEX TYPE Document SET
|
|
228
|
+
title = 'AI Research Paper',
|
|
229
|
+
embedding = [0.1, 0.2, 0.3, ...], # Your vector embeddings
|
|
230
|
+
content = 'Full document text...'
|
|
231
|
+
""")
|
|
232
|
+
|
|
233
|
+
# Vector similarity search
|
|
234
|
+
result = db.query("sql", """
|
|
235
|
+
SELECT title, content,
|
|
236
|
+
cosine_similarity(embedding, [0.1, 0.2, 0.3, ...]) as similarity
|
|
237
|
+
FROM Document
|
|
238
|
+
ORDER BY similarity DESC
|
|
239
|
+
LIMIT 10
|
|
240
|
+
""")
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Configuration Options
|
|
244
|
+
|
|
245
|
+
| Parameter | Type | Default | Description |
|
|
246
|
+
|-----------|------|---------|-------------|
|
|
247
|
+
| `host` | str | "localhost" | ArcadeDB server hostname |
|
|
248
|
+
| `port` | int | 2480 | ArcadeDB server port |
|
|
249
|
+
| `username` | str | "root" | Database username |
|
|
250
|
+
| `password` | str | None | Database password |
|
|
251
|
+
| `database` | str | None | Database name |
|
|
252
|
+
| `use_ssl` | bool | False | Enable SSL connection |
|
|
253
|
+
| `timeout` | int | 30 | Request timeout in seconds |
|
|
254
|
+
| `pool_size` | int | 10 | Connection pool size |
|
|
255
|
+
|
|
256
|
+
## Requirements
|
|
257
|
+
|
|
258
|
+
- **Python**: 3.8 or higher
|
|
259
|
+
- **ArcadeDB**: Version 23.10 or higher
|
|
260
|
+
- **Dependencies**:
|
|
261
|
+
- `requests` >= 2.25.0
|
|
262
|
+
- `retry` >= 0.9.2
|
|
263
|
+
|
|
264
|
+
## Development
|
|
265
|
+
|
|
266
|
+
### Setting up Development Environment
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Clone the repository
|
|
270
|
+
git clone https://github.com/stevereiner/arcadedb-python.git
|
|
271
|
+
cd arcadedb-python
|
|
272
|
+
|
|
273
|
+
# Install uv (if not already installed)
|
|
274
|
+
pip install uv
|
|
275
|
+
|
|
276
|
+
# Create virtual environment and install dependencies
|
|
277
|
+
uv venv
|
|
278
|
+
uv pip install -e .[dev]
|
|
279
|
+
|
|
280
|
+
# Run tests
|
|
281
|
+
uv run pytest
|
|
282
|
+
|
|
283
|
+
# Run linting
|
|
284
|
+
uv run black .
|
|
285
|
+
uv run isort .
|
|
286
|
+
uv run flake8
|
|
287
|
+
uv run mypy arcadedb_python
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Building the Package
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Build the package
|
|
294
|
+
uv build
|
|
295
|
+
|
|
296
|
+
# Check the built package
|
|
297
|
+
uv run twine check dist/*
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Running ArcadeDB for Development
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Using Docker
|
|
304
|
+
docker run -d --name arcadedb \
|
|
305
|
+
-p 2480:2480 -p 2424:2424 \
|
|
306
|
+
-e JAVA_OPTS="-Darcadedb.server.rootPassword=playwithdata" \
|
|
307
|
+
arcadedata/arcadedb:latest
|
|
308
|
+
|
|
309
|
+
# Access ArcadeDB Studio at http://localhost:2480
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Contributing
|
|
313
|
+
|
|
314
|
+
We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.
|
|
315
|
+
|
|
316
|
+
1. Fork the repository
|
|
317
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
318
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
319
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
320
|
+
5. Open a Pull Request
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
325
|
+
|
|
326
|
+
## Links
|
|
327
|
+
|
|
328
|
+
### This Project
|
|
329
|
+
- **GitHub**: https://github.com/stevereiner/arcadedb-python
|
|
330
|
+
- **PyPI**: https://pypi.org/project/arcadedb-python/
|
|
331
|
+
- **Issues**: https://github.com/stevereiner/arcadedb-python/issues
|
|
332
|
+
|
|
333
|
+
### ArcadeDB
|
|
334
|
+
- **Homepage**: https://arcadedb.com
|
|
335
|
+
- **Documentation**: https://docs.arcadedb.com
|
|
336
|
+
- **Main Repository**: https://github.com/ArcadeData/arcadedb
|
|
337
|
+
|
|
338
|
+
### Original Contributors
|
|
339
|
+
- **Adams Rosales**: https://github.com/adaros92/arcadedb-python-driver
|
|
340
|
+
- **ExtReMLapin**: https://github.com/ExtReMLapin
|
|
341
|
+
|
|
342
|
+
## Changelog
|
|
343
|
+
|
|
344
|
+
See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
arcadedb_python/__init__.py,sha256=XyDDwYw1dSEfjoyqrli9bRD8uCnYZIKtGlgvZnwbjJE,1224
|
|
2
|
+
arcadedb_python/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
arcadedb_python/api/client.py,sha256=28AWHzrJQBgOsJmhAFnlNa-WkU-mh5Etgq77bEhuOxA,3058
|
|
4
|
+
arcadedb_python/api/config.py,sha256=sjaGuf3xS516e3nTA1oNzJ2ybvJCC0KYyk4q01BSSls,1078
|
|
5
|
+
arcadedb_python/api/sync.py,sha256=w7cwB97CFaFcXDYHTU0NuxibGGOBDGeaCSK8IXS28jY,4656
|
|
6
|
+
arcadedb_python/dao/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
arcadedb_python/dao/database.py,sha256=c0Ag8fhIkA9_syUtlmQWm_GXglCoGnJPVV6t7gJETOA,11819
|
|
8
|
+
arcadedb_python/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
arcadedb_python/model/database.py,sha256=XI24QKmTlYjd8jLZan-RMeo-KZf86niVCW_lp3L9ZEY,101
|
|
10
|
+
arcadedb_python/model/request.py,sha256=qpnPmx2f3BAro0MMT9MWSvKC1OXnfeG2bbOY78J982Q,395
|
|
11
|
+
arcadedb_python-0.2.0.dist-info/METADATA,sha256=GB7FbKLYDt4uCONvZ1CSLjPh0cbLVigyhfMifLb3izM,10106
|
|
12
|
+
arcadedb_python-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
13
|
+
arcadedb_python-0.2.0.dist-info/licenses/LICENSE,sha256=F96EzotgWhhpnQTW2TcdoqrMDir1jyEo6H915tGQ-QE,11524
|
|
14
|
+
arcadedb_python-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|