graphitedb 0.1.2__py3-none-any.whl → 0.2__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.
- graphite/__init__.py +26 -687
- graphite/engine.py +564 -0
- graphite/exceptions.py +89 -0
- graphite/instances.py +50 -0
- graphite/migration.py +104 -0
- graphite/parser.py +228 -0
- graphite/query.py +199 -0
- graphite/serialization.py +174 -0
- graphite/types.py +65 -0
- graphite/utils.py +34 -0
- {graphitedb-0.1.2.dist-info → graphitedb-0.2.dist-info}/METADATA +2 -4
- graphitedb-0.2.dist-info/RECORD +15 -0
- {graphitedb-0.1.2.dist-info → graphitedb-0.2.dist-info}/top_level.txt +0 -1
- __init__.py +0 -0
- graphitedb-0.1.2.dist-info/RECORD +0 -7
- {graphitedb-0.1.2.dist-info → graphitedb-0.2.dist-info}/WHEEL +0 -0
- {graphitedb-0.1.2.dist-info → graphitedb-0.2.dist-info}/licenses/LICENSE +0 -0
graphite/types.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Data, relation, and node type classes for Graphite database
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import List, Optional, Any
|
|
8
|
+
|
|
9
|
+
class DataType(Enum):
|
|
10
|
+
"""
|
|
11
|
+
Valid data types in graphite. Used in nodes and relations properties.
|
|
12
|
+
"""
|
|
13
|
+
STRING = "string"
|
|
14
|
+
INT = "int"
|
|
15
|
+
DATE = "date"
|
|
16
|
+
FLOAT = "float"
|
|
17
|
+
BOOL = "bool"
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class Field:
|
|
21
|
+
"""
|
|
22
|
+
A data field (property) for nodes and relations.
|
|
23
|
+
"""
|
|
24
|
+
name: str
|
|
25
|
+
dtype: DataType
|
|
26
|
+
default: Any = None
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class NodeType:
|
|
30
|
+
"""
|
|
31
|
+
A defined node type (with ``node ...`` block in dsl or ``GraphiteEngine.define_node()``).
|
|
32
|
+
Each node type has a name (in snake_case usually), and optional list of fields (properties).
|
|
33
|
+
Supports optional parent node type.
|
|
34
|
+
"""
|
|
35
|
+
name: str
|
|
36
|
+
fields: List[Field] = field(default_factory=list)
|
|
37
|
+
parent: Optional[NodeType] = None
|
|
38
|
+
|
|
39
|
+
def get_all_fields(self) -> List[Field]:
|
|
40
|
+
"""Get all fields including inherited ones"""
|
|
41
|
+
fields = self.fields.copy()
|
|
42
|
+
if self.parent:
|
|
43
|
+
fields = self.parent.get_all_fields() + fields
|
|
44
|
+
return fields
|
|
45
|
+
|
|
46
|
+
def __hash__(self):
|
|
47
|
+
return hash(self.name)
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class RelationType:
|
|
51
|
+
"""
|
|
52
|
+
A defined relation type (with ``relation ...`` block in dsl or
|
|
53
|
+
``GraphiteEngine.define_relation()``). Each relation type has a name (in UPPER_SNAKE_CASE
|
|
54
|
+
usually), and optional list of fields (properties). A relation type can be from one node
|
|
55
|
+
type to another.
|
|
56
|
+
"""
|
|
57
|
+
name: str
|
|
58
|
+
from_type: str
|
|
59
|
+
to_type: str
|
|
60
|
+
fields: List[Field] = field(default_factory=list)
|
|
61
|
+
reverse_name: Optional[str] = None
|
|
62
|
+
is_bidirectional: bool = False
|
|
63
|
+
|
|
64
|
+
def __hash__(self):
|
|
65
|
+
return hash(self.name)
|
graphite/utils.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utility functions, accessible directly from ``graphite``
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
class SecurityWarning(Warning):
|
|
6
|
+
"""A security warning."""
|
|
7
|
+
|
|
8
|
+
def node(node_type: str, **fields) -> str:
|
|
9
|
+
"""Helper function to create node definitions"""
|
|
10
|
+
lines = [f"node {node_type}"]
|
|
11
|
+
for field_name, field_type in fields.items():
|
|
12
|
+
lines.append(f"{field_name}: {field_type}")
|
|
13
|
+
return "\n".join(lines)
|
|
14
|
+
|
|
15
|
+
def relation(name: str, from_type: str, to_type: str, **kwargs) -> str:
|
|
16
|
+
"""Helper function to create relation definitions"""
|
|
17
|
+
lines = [f"relation {name}"]
|
|
18
|
+
if kwargs.get('both'):
|
|
19
|
+
lines[0] += " both"
|
|
20
|
+
if kwargs.get('reverse'):
|
|
21
|
+
lines[0] += f" reverse {kwargs['reverse']}"
|
|
22
|
+
|
|
23
|
+
direction = "->" if not kwargs.get('both') else "-"
|
|
24
|
+
lines.append(f"{from_type} {direction} {to_type}")
|
|
25
|
+
|
|
26
|
+
for field_name, field_type in kwargs.get('fields', {}).items():
|
|
27
|
+
lines.append(f"{field_name}: {field_type}")
|
|
28
|
+
|
|
29
|
+
return "\n".join(lines)
|
|
30
|
+
|
|
31
|
+
def engine():
|
|
32
|
+
"""Create graphite engine instance"""
|
|
33
|
+
from .engine import GraphiteEngine # pylint: disable=import-outside-toplevel
|
|
34
|
+
return GraphiteEngine()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphitedb
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A clean graph database engine
|
|
3
|
+
Version: 0.2
|
|
4
|
+
Summary: A clean, embedded graph database engine for Python.
|
|
5
5
|
Author-email: Mahan Khalili <khalili1388mahan@gmail.com>
|
|
6
6
|
Maintainer-email: Mahan Khalili <khalili1388mahan@gmail.com>
|
|
7
7
|
License-Expression: MIT
|
|
@@ -201,5 +201,3 @@ def example_complete_dsl_loading():
|
|
|
201
201
|
```
|
|
202
202
|
|
|
203
203
|
More examples are available in `example.py` in the GitHub repository.
|
|
204
|
-
::contentReference[oaicite:0]{index=0}
|
|
205
|
-
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
graphite/__init__.py,sha256=ap6NYxeoJyYqII72mYpwL-Mql5PNZpEEw25UuiUxZHc,862
|
|
2
|
+
graphite/engine.py,sha256=qaDifjudUF5MFnoh3HyHL-lrZ18zjCaD61nCN-D30yU,16965
|
|
3
|
+
graphite/exceptions.py,sha256=_iA9JZR4oqev6p_CMHbAdzh3LAisOgQzn7ylnECQQQ8,2744
|
|
4
|
+
graphite/instances.py,sha256=9HD-k02EdVL1HrBZ7s092j2yk7j-GJNkWGn3wHilKk4,1212
|
|
5
|
+
graphite/migration.py,sha256=0-jgvJhi_0BTLjHjSOoAuBOTusXrjwnByX1e_SO-aRI,3118
|
|
6
|
+
graphite/parser.py,sha256=LZt5To7x6YQh01NF6hRGYemFYb-Vh-_RKZ39OWpwVwY,6771
|
|
7
|
+
graphite/query.py,sha256=i8u6O7dRXFv5FjsDYoo2cJX2szsKwJZh_6KIcjv6Fw4,5869
|
|
8
|
+
graphite/serialization.py,sha256=ku7CiEECgRoCDW2FQBFWXo-8FPP_JO2jpVa17FkglHY,4910
|
|
9
|
+
graphite/types.py,sha256=d5PwuRrLAXV0KWsTuGKF7HdFwLeu6zZ3ok5hjRlBxT4,1643
|
|
10
|
+
graphite/utils.py,sha256=3p5TMRHXP7gEvdD2Xl-_tjk03vCuo8h52kaNp3DFUTA,1045
|
|
11
|
+
graphitedb-0.2.dist-info/licenses/LICENSE,sha256=3n5Zi5QXqsnus7yX3xKY7wKtX7Ios_ofbTxdhSUz0dA,1070
|
|
12
|
+
graphitedb-0.2.dist-info/METADATA,sha256=u8VKjxYJTc9N9yn_dy9uiOCKYB8bchHa3JcNXQoGwUc,4797
|
|
13
|
+
graphitedb-0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
14
|
+
graphitedb-0.2.dist-info/top_level.txt,sha256=QPrpQuMV9WIM20kS6NN7OWkIzypVFiSTICJLsYYkJ1w,9
|
|
15
|
+
graphitedb-0.2.dist-info/RECORD,,
|
__init__.py
DELETED
|
File without changes
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
graphite/__init__.py,sha256=g7eX0jbvKOW0deFbrmj8Y21FQnrRQw5lol0EgeZMbsU,20588
|
|
3
|
-
graphitedb-0.1.2.dist-info/licenses/LICENSE,sha256=3n5Zi5QXqsnus7yX3xKY7wKtX7Ios_ofbTxdhSUz0dA,1070
|
|
4
|
-
graphitedb-0.1.2.dist-info/METADATA,sha256=cTQ7lwk3C9iRFZPZsydjZidCqB2rX6JLMJPFuRBUJ3Q,4820
|
|
5
|
-
graphitedb-0.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
graphitedb-0.1.2.dist-info/top_level.txt,sha256=3a6k71PT31c_EyE1n54UPWzTLUKEUx8PmMNA4uyTByM,18
|
|
7
|
-
graphitedb-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|