Skip to content

Commit 67749fe

Browse files
Add agent package (#108)
1 parent acea37f commit 67749fe

29 files changed

Lines changed: 3409 additions & 200 deletions

.pydocstyle.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pydocstyle]
2+
match = (?!(test)?_).*\.py

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[mypy]
22
disallow_any_explicit = True
3+
enable_recursive_aliases = True
34
strict = True

poetry.lock

Lines changed: 275 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ mypy = "^0.981"
2727
types-python-dateutil = "^2.8.19"
2828
types-requests = "^2.28.11"
2929
types-simplejson = "^3.17.7"
30+
pytest = "^7.1.3"
31+
hypothesis = "^6.54.6"
32+
jsonschema = "^4.16.0"
33+
types-jsonschema = "^4.16.1"
3034

src/elimity_insights_client/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from elimity_insights_client._elimity_insights_client import (
99
AttributeAssignment,
10-
AttributeType,
1110
BooleanValue,
1211
Certificate,
1312
Client,
@@ -17,18 +16,21 @@
1716
DateTimeValue,
1817
DateValue,
1918
DomainGraph,
20-
DomainGraphSchema,
2119
Entity,
22-
EntityType,
2320
Level,
2421
NumberValue,
2522
Relationship,
26-
RelationshipAttributeType,
2723
StringValue,
2824
TimeValue,
29-
Type,
3025
Value,
3126
)
27+
from elimity_insights_client._domain_graph_schema import (
28+
AttributeType,
29+
DomainGraphSchema,
30+
EntityType,
31+
RelationshipAttributeType,
32+
Type,
33+
)
3234

3335
__all__ = [
3436
"AttributeAssignment",
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
from typing import List
2+
3+
from typing_extensions import TypedDict, NotRequired
4+
5+
from elimity_insights_client._domain_graph_schema import (
6+
DomainGraphSchema,
7+
AttributeType,
8+
RelationshipAttributeType,
9+
EntityType,
10+
Type,
11+
)
12+
from elimity_insights_client._util import map_list
13+
14+
AttributeTypeDict = TypedDict(
15+
"AttributeTypeDict",
16+
{
17+
"archived": bool,
18+
"description": str,
19+
"entityTypeId": str,
20+
"id": str,
21+
"name": str,
22+
"type": str,
23+
},
24+
)
25+
EntityTypeDict = TypedDict(
26+
"EntityTypeDict",
27+
{
28+
"anonymized": bool,
29+
"icon": str,
30+
"id": str,
31+
"plural": str,
32+
"singular": str,
33+
},
34+
)
35+
RelationshipAttributeTypeDict = TypedDict(
36+
"RelationshipAttributeTypeDict",
37+
{
38+
"archived": bool,
39+
"childType": str,
40+
"description": NotRequired[str],
41+
"id": str,
42+
"name": str,
43+
"parentType": str,
44+
"type": str,
45+
},
46+
)
47+
DomainGraphSchemaDict = TypedDict(
48+
"DomainGraphSchemaDict",
49+
{
50+
"entityAttributeTypes": List[AttributeTypeDict],
51+
"entityTypes": List[EntityTypeDict],
52+
"relationshipAttributeTypes": List[RelationshipAttributeTypeDict],
53+
},
54+
)
55+
56+
57+
def decode_domain_graph_schema(json: DomainGraphSchemaDict) -> DomainGraphSchema:
58+
"""Decode the given JSON value to a domain graph schema."""
59+
attribute_types = json["entityAttributeTypes"]
60+
attribute_types_ = map_list(_decode_attribute_type, attribute_types)
61+
entity_types = json["entityTypes"]
62+
entity_types_ = map_list(_decode_entity_type, entity_types)
63+
relationship_attribute_types = json["relationshipAttributeTypes"]
64+
relationship_attribute_types_ = map_list(
65+
_decode_relationship_attribute_types, relationship_attribute_types
66+
)
67+
return DomainGraphSchema(
68+
attribute_types_, entity_types_, relationship_attribute_types_
69+
)
70+
71+
72+
def _decode_attribute_type(json: AttributeTypeDict) -> AttributeType:
73+
archived = json["archived"]
74+
description = json["description"]
75+
entity_type = json["entityTypeId"]
76+
id_ = json["id"]
77+
name = json["name"]
78+
type_ = json["type"]
79+
type__ = _decode_type(type_)
80+
return AttributeType(archived, description, entity_type, id_, name, type__)
81+
82+
83+
def _decode_entity_type(json: EntityTypeDict) -> EntityType:
84+
anonymized = json["anonymized"]
85+
icon = json["icon"]
86+
id = json["id"]
87+
plural = json["plural"]
88+
singular = json["singular"]
89+
return EntityType(anonymized, icon, id, plural, singular)
90+
91+
92+
def _decode_relationship_attribute_types(
93+
json: RelationshipAttributeTypeDict,
94+
) -> RelationshipAttributeType:
95+
archived = json["archived"]
96+
description = json.get("description", "")
97+
from_entity_type = json["parentType"]
98+
id_ = json["id"]
99+
name = json["name"]
100+
to_entity_type = json["childType"]
101+
type_ = json["type"]
102+
type__ = _decode_type(type_)
103+
return RelationshipAttributeType(
104+
archived, description, from_entity_type, id_, name, to_entity_type, type__
105+
)
106+
107+
108+
def _decode_type(json: str) -> Type:
109+
if json == "boolean":
110+
return Type.BOOLEAN
111+
elif json == "date":
112+
return Type.DATE
113+
elif json == "dateTime":
114+
return Type.DATE_TIME
115+
elif json == "number":
116+
return Type.NUMBER
117+
elif json == "string":
118+
return Type.STRING
119+
else:
120+
return Type.TIME
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from dataclasses import dataclass
2+
from enum import Enum, auto
3+
from typing import List
4+
5+
6+
@dataclass
7+
class AttributeType:
8+
"""Attribute type for an entity type."""
9+
10+
archived: bool
11+
description: str
12+
entity_type: str
13+
id: str
14+
name: str
15+
type: "Type"
16+
17+
18+
@dataclass
19+
class DomainGraphSchema:
20+
"""Schema determining valid domain graphs."""
21+
22+
attribute_types: List[AttributeType]
23+
entity_types: List["EntityType"]
24+
relationship_attribute_types: List["RelationshipAttributeType"]
25+
26+
27+
@dataclass
28+
class EntityType:
29+
"""Type of an entity."""
30+
31+
anonymized: bool
32+
icon: str
33+
id: str
34+
plural: str
35+
singular: str
36+
37+
38+
@dataclass
39+
class RelationshipAttributeType:
40+
"""Attribute type for relationships between entities of specific types."""
41+
42+
archived: bool
43+
description: str
44+
from_entity_type: str
45+
id: str
46+
name: str
47+
to_entity_type: str
48+
type: "Type"
49+
50+
51+
class Type(Enum):
52+
"""Type of an attribute type, determining valid assignment values."""
53+
54+
BOOLEAN = auto()
55+
DATE = auto()
56+
DATE_TIME = auto()
57+
NUMBER = auto()
58+
STRING = auto()
59+
TIME = auto()

0 commit comments

Comments
 (0)