graflo 1.3.3__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.
- graflo/README.md +18 -0
- graflo/__init__.py +70 -0
- graflo/architecture/__init__.py +38 -0
- graflo/architecture/actor.py +1120 -0
- graflo/architecture/actor_util.py +450 -0
- graflo/architecture/edge.py +297 -0
- graflo/architecture/onto.py +374 -0
- graflo/architecture/resource.py +161 -0
- graflo/architecture/schema.py +136 -0
- graflo/architecture/transform.py +292 -0
- graflo/architecture/util.py +93 -0
- graflo/architecture/vertex.py +586 -0
- graflo/caster.py +655 -0
- graflo/cli/__init__.py +14 -0
- graflo/cli/ingest.py +194 -0
- graflo/cli/manage_dbs.py +197 -0
- graflo/cli/plot_schema.py +132 -0
- graflo/cli/xml2json.py +93 -0
- graflo/data_source/__init__.py +48 -0
- graflo/data_source/api.py +339 -0
- graflo/data_source/base.py +97 -0
- graflo/data_source/factory.py +298 -0
- graflo/data_source/file.py +133 -0
- graflo/data_source/memory.py +72 -0
- graflo/data_source/registry.py +82 -0
- graflo/data_source/sql.py +185 -0
- graflo/db/__init__.py +44 -0
- graflo/db/arango/__init__.py +22 -0
- graflo/db/arango/conn.py +1026 -0
- graflo/db/arango/query.py +180 -0
- graflo/db/arango/util.py +88 -0
- graflo/db/conn.py +377 -0
- graflo/db/connection/__init__.py +6 -0
- graflo/db/connection/config_mapping.py +18 -0
- graflo/db/connection/onto.py +688 -0
- graflo/db/connection/wsgi.py +29 -0
- graflo/db/manager.py +119 -0
- graflo/db/neo4j/__init__.py +16 -0
- graflo/db/neo4j/conn.py +639 -0
- graflo/db/postgres/__init__.py +156 -0
- graflo/db/postgres/conn.py +425 -0
- graflo/db/postgres/resource_mapping.py +139 -0
- graflo/db/postgres/schema_inference.py +245 -0
- graflo/db/postgres/types.py +148 -0
- graflo/db/tigergraph/__init__.py +9 -0
- graflo/db/tigergraph/conn.py +2212 -0
- graflo/db/util.py +49 -0
- graflo/filter/__init__.py +21 -0
- graflo/filter/onto.py +525 -0
- graflo/logging.conf +22 -0
- graflo/onto.py +190 -0
- graflo/plot/__init__.py +17 -0
- graflo/plot/plotter.py +556 -0
- graflo/util/__init__.py +23 -0
- graflo/util/chunker.py +751 -0
- graflo/util/merge.py +150 -0
- graflo/util/misc.py +37 -0
- graflo/util/onto.py +332 -0
- graflo/util/transform.py +448 -0
- graflo-1.3.3.dist-info/METADATA +190 -0
- graflo-1.3.3.dist-info/RECORD +64 -0
- graflo-1.3.3.dist-info/WHEEL +4 -0
- graflo-1.3.3.dist-info/entry_points.txt +5 -0
- graflo-1.3.3.dist-info/licenses/LICENSE +126 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class WSGIConfig(BaseSettings):
|
|
8
|
+
"""Configuration for WSGI connections.
|
|
9
|
+
|
|
10
|
+
Note: WSGI is not a database db, so it doesn't inherit from DBConfig.
|
|
11
|
+
This is kept separate from database db configurations.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
model_config = SettingsConfigDict(
|
|
15
|
+
env_prefix="WSGI_",
|
|
16
|
+
case_sensitive=False,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
uri: str | None = Field(default=None, description="WSGI URI")
|
|
20
|
+
path: str = Field(default="/", description="WSGI path")
|
|
21
|
+
paths: Dict[str, str] = Field(
|
|
22
|
+
default_factory=dict, description="WSGI paths mapping"
|
|
23
|
+
)
|
|
24
|
+
listen_addr: str = Field(default="0.0.0.0", description="Listen address")
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def from_docker_env(cls, docker_dir: str | None = None) -> "WSGIConfig":
|
|
28
|
+
"""WSGI config doesn't typically use docker env files."""
|
|
29
|
+
raise NotImplementedError("WSGI config doesn't support from_docker_env")
|
graflo/db/manager.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Database connection manager for graph and source databases.
|
|
2
|
+
|
|
3
|
+
This module provides a connection manager for handling database connections
|
|
4
|
+
to different database implementations (ArangoDB, Neo4j, PostgreSQL, etc.).
|
|
5
|
+
It manages connection lifecycle and configuration.
|
|
6
|
+
|
|
7
|
+
Key Components:
|
|
8
|
+
- ConnectionManager: Main class for managing database connections
|
|
9
|
+
- DBType: Enum for supported database types
|
|
10
|
+
|
|
11
|
+
The manager supports:
|
|
12
|
+
- Target databases (ArangoDB, Neo4j, TigerGraph) - OUTPUT
|
|
13
|
+
- Source databases (PostgreSQL, MySQL, MongoDB, etc.) - INPUT
|
|
14
|
+
- Connection configuration
|
|
15
|
+
- Context manager interface
|
|
16
|
+
- Automatic connection cleanup
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
>>> from graflo.db.connection.onto import ArangoConfig
|
|
20
|
+
>>> config = ArangoConfig.from_env()
|
|
21
|
+
>>> with ConnectionManager(connection_config=config) as conn:
|
|
22
|
+
... conn.execute("FOR doc IN collection RETURN doc")
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from graflo.db.arango.conn import ArangoConnection
|
|
26
|
+
from graflo.db.connection.onto import DBConfig, DBType, TARGET_DATABASES
|
|
27
|
+
from graflo.db.neo4j.conn import Neo4jConnection
|
|
28
|
+
from graflo.db.tigergraph.conn import TigerGraphConnection
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ConnectionManager:
|
|
32
|
+
"""Manager for database connections (both graph and source databases).
|
|
33
|
+
|
|
34
|
+
This class manages database connections to different database
|
|
35
|
+
implementations. It provides a context manager interface for safe
|
|
36
|
+
connection handling and automatic cleanup.
|
|
37
|
+
|
|
38
|
+
Supports:
|
|
39
|
+
- Target databases (OUTPUT): ArangoDB, Neo4j, TigerGraph
|
|
40
|
+
- Source databases (INPUT): PostgreSQL, MySQL, MongoDB, etc.
|
|
41
|
+
|
|
42
|
+
Attributes:
|
|
43
|
+
target_conn_mapping: Mapping of target database types to connection classes
|
|
44
|
+
config: Connection configuration
|
|
45
|
+
working_db: Current working database name
|
|
46
|
+
conn: Active database connection
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# Target database connections (OUTPUT)
|
|
50
|
+
target_conn_mapping = {
|
|
51
|
+
DBType.ARANGO: ArangoConnection,
|
|
52
|
+
DBType.NEO4J: Neo4jConnection,
|
|
53
|
+
DBType.TIGERGRAPH: TigerGraphConnection,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Source database connections (INPUT) - to be implemented
|
|
57
|
+
# source_conn_mapping = {
|
|
58
|
+
# DBType.POSTGRES: PostgresConnection,
|
|
59
|
+
# DBType.MYSQL: MySQLConnection,
|
|
60
|
+
# DBType.MONGODB: MongoDBConnection,
|
|
61
|
+
# }
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
connection_config: DBConfig,
|
|
66
|
+
**kwargs,
|
|
67
|
+
):
|
|
68
|
+
"""Initialize the connection manager.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
connection_config: Database connection configuration
|
|
72
|
+
**kwargs: Additional configuration parameters
|
|
73
|
+
"""
|
|
74
|
+
self.config: DBConfig = connection_config
|
|
75
|
+
self.working_db = kwargs.pop("working_db", None)
|
|
76
|
+
self.conn = None
|
|
77
|
+
|
|
78
|
+
def __enter__(self):
|
|
79
|
+
"""Enter the context manager.
|
|
80
|
+
|
|
81
|
+
Creates and returns a new database connection.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
Connection: Database connection instance
|
|
85
|
+
"""
|
|
86
|
+
# Check if database can be used as target
|
|
87
|
+
if not self.config.can_be_target():
|
|
88
|
+
raise ValueError(
|
|
89
|
+
f"Database type '{self.config.connection_type}' cannot be used as a target. "
|
|
90
|
+
f"Only these types can be targets: {[t.value for t in TARGET_DATABASES]}"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
db_type = self.config.connection_type
|
|
94
|
+
cls = self.target_conn_mapping[db_type]
|
|
95
|
+
|
|
96
|
+
if self.working_db is not None:
|
|
97
|
+
self.config.database = self.working_db
|
|
98
|
+
self.conn = cls(config=self.config)
|
|
99
|
+
return self.conn
|
|
100
|
+
|
|
101
|
+
def close(self):
|
|
102
|
+
"""Close the database connection.
|
|
103
|
+
|
|
104
|
+
Closes the active connection and performs any necessary cleanup.
|
|
105
|
+
"""
|
|
106
|
+
if self.conn is not None:
|
|
107
|
+
self.conn.close()
|
|
108
|
+
|
|
109
|
+
def __exit__(self, exc_type, exc_value, exc_traceback):
|
|
110
|
+
"""Exit the context manager.
|
|
111
|
+
|
|
112
|
+
Ensures the connection is properly closed when exiting the context.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
exc_type: Exception type if an exception occurred
|
|
116
|
+
exc_value: Exception value if an exception occurred
|
|
117
|
+
exc_traceback: Exception traceback if an exception occurred
|
|
118
|
+
"""
|
|
119
|
+
self.close()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Neo4j database implementation.
|
|
2
|
+
|
|
3
|
+
This package provides Neo4j-specific implementations of the database interface,
|
|
4
|
+
including connection management, query execution, and utility functions.
|
|
5
|
+
|
|
6
|
+
Key Components:
|
|
7
|
+
- Neo4jConnection: Neo4j connection implementation
|
|
8
|
+
- Query: Cypher query execution and profiling
|
|
9
|
+
- Util: Neo4j-specific utility functions
|
|
10
|
+
|
|
11
|
+
Example:
|
|
12
|
+
>>> from graflo.db.neo4j import Neo4jConnection
|
|
13
|
+
>>> conn = Neo4jConnection(config)
|
|
14
|
+
>>> result = conn.execute("MATCH (n:User) RETURN n")
|
|
15
|
+
>>> nodes = result.data()
|
|
16
|
+
"""
|