MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / GraphLite

Class GraphLite

bindings/python/graphlite/graphlite.py:183–374  ·  view source on GitHub ↗

GraphLite database connection Example: >>> db = GraphLite("./mydb") >>> session = db.create_session("admin") >>> result = db.query(session, "MATCH (n) RETURN n") >>> print(result.rows) >>> db.close() Or use as context manager: >>> with G

Source from the content-addressed store, hash-verified

181
182
183class GraphLite:
184 """
185 GraphLite database connection
186
187 Example:
188 >>> db = GraphLite("./mydb")
189 >>> session = db.create_session("admin")
190 >>> result = db.query(session, "MATCH (n) RETURN n")
191 >>> print(result.rows)
192 >>> db.close()
193
194 Or use as context manager:
195 >>> with GraphLite("./mydb") as db:
196 ... session = db.create_session("admin")
197 ... result = db.query(session, "MATCH (n) RETURN n")
198 """
199
200 def __init__(self, path: str):
201 """
202 Open a GraphLite database
203
204 Args:
205 path: Path to database directory
206
207 Raises:
208 GraphLiteError: If database cannot be opened
209 """
210 self._db = None
211 self._sessions = set()
212
213 error = ctypes.c_int(0)
214 self._db = _lib.graphlite_open(path.encode('utf-8'), ctypes.byref(error))
215
216 if not self._db:
217 raise GraphLiteError(
218 ErrorCode(error.value),
219 f"Failed to open database at {path}"
220 )
221
222 def create_session(self, username: str) -> str:
223 """
224 Create a new session for the given user
225
226 Args:
227 username: Username for the session
228
229 Returns:
230 Session ID string
231
232 Raises:
233 GraphLiteError: If session creation fails
234 """
235 if not self._db:
236 raise GraphLiteError(ErrorCode.NULL_POINTER, "Database is closed")
237
238 error = ctypes.c_int(0)
239 session_id_ptr = _lib.graphlite_create_session(
240 self._db,

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected