ladybug 0.23.0.dev20261111__cp315-cp315-win_amd64.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.
ladybug/__init__.py ADDED
@@ -0,0 +1,106 @@
1
+ # ruff: noqa
2
+ """
3
+ # Lbug Python API bindings.
4
+
5
+ This package provides a Python API for Lbug graph database management system.
6
+
7
+ To install the package, run:
8
+ ```
9
+ python3 -m pip install ladybug
10
+ ```
11
+
12
+ Example usage:
13
+ ```python
14
+ import ladybug as lb
15
+
16
+ db = lb.Database("./test")
17
+ conn = lb.Connection(db)
18
+
19
+ # Define the schema
20
+ conn.execute("CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))")
21
+ conn.execute("CREATE NODE TABLE City(name STRING, population INT64, PRIMARY KEY (name))")
22
+ conn.execute("CREATE REL TABLE Follows(FROM User TO User, since INT64)")
23
+ conn.execute("CREATE REL TABLE LivesIn(FROM User TO City)")
24
+
25
+ # Load some data
26
+ conn.execute('COPY User FROM "user.csv"')
27
+ conn.execute('COPY City FROM "city.csv"')
28
+ conn.execute('COPY Follows FROM "follows.csv"')
29
+ conn.execute('COPY LivesIn FROM "lives-in.csv"')
30
+
31
+ # Query the data
32
+ results = conn.execute("MATCH (u:User) RETURN u.name, u.age;")
33
+ while results.has_next():
34
+ print(results.get_next())
35
+ ```
36
+
37
+ The dataset used in this example can be found [here](https://github.com/LadybugDB/ladybug/tree/master/dataset/demo-db/csv).
38
+
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+
44
+ # start delvewheel patch
45
+ def _delvewheel_patch_1_13_2():
46
+ import os
47
+ if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'ladybug.libs'))):
48
+ os.add_dll_directory(libs_dir)
49
+
50
+
51
+ _delvewheel_patch_1_13_2()
52
+ del _delvewheel_patch_1_13_2
53
+ # end delvewheel patch
54
+
55
+ from pathlib import Path
56
+
57
+ # In local dev/test runs the optional pybind extension is built under build/ladybug
58
+ # while the package sources live in src_py. Extend the package path so
59
+ # `from . import _lbug` can discover the built extension without installation.
60
+ _pkg_dir = Path(__file__).resolve().parent
61
+ _repo_build_pkg_dir = _pkg_dir.parent / "build" / "ladybug"
62
+ if _repo_build_pkg_dir.is_dir():
63
+ __path__.append(str(_repo_build_pkg_dir))
64
+
65
+ from ._backend import get_capi_module, get_pybind_module # noqa: E402
66
+
67
+ from .async_connection import AsyncConnection # noqa: E402
68
+ from .connection import Connection # noqa: E402
69
+ from .database import Database # noqa: E402
70
+ from .prepared_statement import PreparedStatement # noqa: E402
71
+ from .query_result import ArrowQueryResult, CSRResult, QueryResult # noqa: E402
72
+ from .types import ArrowRelTableLayout, Type # noqa: E402
73
+
74
+ _VERSION_INFO: tuple[str, int] | None = None
75
+
76
+
77
+ def _get_version_info() -> tuple[str, int]:
78
+ global _VERSION_INFO
79
+ if _VERSION_INFO is None:
80
+ _VERSION_INFO = (Database.get_version(), Database.get_storage_version())
81
+ return _VERSION_INFO
82
+
83
+
84
+ def __getattr__(name: str) -> str | int:
85
+ if name == "version" or name == "__version__":
86
+ return _get_version_info()[0]
87
+ if name == "storage_version":
88
+ return _get_version_info()[1]
89
+ msg = f"module {__name__!r} has no attribute {name!r}"
90
+ raise AttributeError(msg)
91
+
92
+
93
+ __all__ = [
94
+ "AsyncConnection",
95
+ "ArrowQueryResult",
96
+ "ArrowRelTableLayout",
97
+ "Connection",
98
+ "CSRResult",
99
+ "Database",
100
+ "PreparedStatement",
101
+ "QueryResult",
102
+ "Type",
103
+ "__version__", # noqa: F822
104
+ "storage_version", # noqa: F822
105
+ "version", # noqa: F822
106
+ ]
ladybug/_backend.py ADDED
@@ -0,0 +1,67 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import sys
5
+ from importlib import import_module
6
+ from typing import Any
7
+
8
+ _CAPI_MODULE: Any | None = None
9
+ _PYBIND_MODULE: Any | None = None
10
+ _PYBIND_IMPORT_ATTEMPTED = False
11
+ _PYBIND_IMPORT_ERROR: ImportError | None = None
12
+
13
+
14
+ def _import_pybind_module() -> Any:
15
+ if sys.platform != "linux":
16
+ return import_module("._lbug", __package__)
17
+
18
+ original_dlopen_flags = sys.getdlopenflags()
19
+ try:
20
+ # Keep pybind's symbols visible to any transitive native extensions
21
+ # without affecting the process-wide import path for the C-API backend.
22
+ sys.setdlopenflags(os.RTLD_GLOBAL | os.RTLD_LAZY)
23
+ return import_module("._lbug", __package__)
24
+ finally:
25
+ sys.setdlopenflags(original_dlopen_flags)
26
+
27
+
28
+ def get_capi_module() -> Any:
29
+ global _CAPI_MODULE
30
+ if _CAPI_MODULE is None:
31
+ _CAPI_MODULE = import_module("._lbug_capi", __package__)
32
+ return _CAPI_MODULE
33
+
34
+
35
+ def get_pybind_module() -> Any | None:
36
+ global _PYBIND_MODULE, _PYBIND_IMPORT_ATTEMPTED, _PYBIND_IMPORT_ERROR
37
+ if _PYBIND_IMPORT_ATTEMPTED:
38
+ return _PYBIND_MODULE
39
+ _PYBIND_IMPORT_ATTEMPTED = True
40
+ try:
41
+ _PYBIND_MODULE = _import_pybind_module()
42
+ except ImportError as exc:
43
+ _PYBIND_MODULE = None
44
+ _PYBIND_IMPORT_ERROR = exc
45
+ return _PYBIND_MODULE
46
+
47
+
48
+ def missing_capi_library_message() -> str:
49
+ """
50
+ Explain why neither backend could load.
51
+
52
+ The C API library is the fallback when the bundled ``_lbug`` extension fails to import, so a missing C API
53
+ library usually hides the real failure. Include that failure, such as a missing OpenSSL 3 runtime.
54
+ """
55
+ msg = (
56
+ "Could not find lbug C API shared library. "
57
+ "Set LBUG_C_API_LIB_PATH or download a shared lib (e.g. run "
58
+ "LBUG_LIB_KIND=shared bash scripts/download_lbug.sh)."
59
+ )
60
+ if _PYBIND_IMPORT_ERROR is None:
61
+ return msg
62
+ msg += f" The bundled _lbug extension, which is tried first, failed to load: {_PYBIND_IMPORT_ERROR}"
63
+ if "libssl" in str(_PYBIND_IMPORT_ERROR) or "libcrypto" in str(
64
+ _PYBIND_IMPORT_ERROR
65
+ ):
66
+ msg += " Ladybug needs an OpenSSL 3 runtime; on macOS, install it with `brew install openssl@3`."
67
+ return msg
Binary file