Skip to content

Commit

Permalink
Merge 'Initial pass on Python API' from Jean Arhancet
Browse files Browse the repository at this point in the history
This pull request introduces the initial setup for the Python bindings
(#248).

- Setup Configuration: Added the Python binding stack, including the
  `pyo3 `crates, `pyproject.toml`, `build.rs`, and other necessary
  files.

- Database Class: Implemented the Database class with a constructor to
  establish a connection and a query function to execute SQL queries.

- Testing: Created `database.db` with a sample users table and two
  entries, as outlined in README.md, and added three pytest functions to
  validate the Python output.

Closes #276
  • Loading branch information
penberg committed Aug 11, 2024
2 parents 4901351 + 3e8f886 commit b3d1db3
Show file tree
Hide file tree
Showing 16 changed files with 861 additions and 4 deletions.
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
/target
/.idea
/.idea

*.so
*.ipynb

# Python
.mypy_cache/
.pytest_cache/
.ruff_cache/
.venv*/
__pycache__/
.coverage
venv
env
.env
.venv

# OS
.DS_Store
112 changes: 110 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[workspace]
resolver = "2"
members = [
"bindings/python",
"bindings/wasm",
"cli",
"sqlite3",
Expand Down
25 changes: 25 additions & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "py-limbo"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[lib]
name = "_limbo"
crate-type = ["cdylib"]

[features]
# must be enabled when building with `cargo build`, maturin enables this automatically
extension-module = ["pyo3/extension-module"]

[dependencies]
anyhow = "1.0"
limbo_core = { path = "../../core" }
pyo3 = { version = "0.22.2", features = ["anyhow", "auto-initialize"] }

[build-dependencies]
version_check = "0.9.5"
# used where logic has to be version/distribution specific, e.g. pypy
pyo3-build-config = { version = "0.22.0" }
4 changes: 4 additions & 0 deletions bindings/python/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
pyo3_build_config::use_pyo3_cfgs();
println!("cargo::rustc-check-cfg=cfg(allocator, values(\"default\", \"mimalloc\"))");
}
29 changes: 29 additions & 0 deletions bindings/python/limbo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from _limbo import (
Connection,
Cursor,
DatabaseError,
DataError,
IntegrityError,
InterfaceError,
InternalError,
NotSupportedError,
OperationalError,
ProgrammingError,
__version__,
connect,
)

__all__ = [
"__version__",
"Connection",
"Cursor",
"InterfaceError",
"DatabaseError",
"DataError",
"OperationalError",
"IntegrityError",
"InternalError",
"ProgrammingError",
"NotSupportedError",
"connect",
]
Loading

0 comments on commit b3d1db3

Please sign in to comment.