Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial pass on Python API #276

Merged
merged 1 commit into from
Aug 11, 2024

Conversation

JeanArhancet
Copy link
Contributor

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.

@JeanArhancet JeanArhancet force-pushed the feat/impl-python-binding branch 3 times, most recently from 81e71f3 to aff52ee Compare August 5, 2024 19:56
@penberg
Copy link
Owner

penberg commented Aug 6, 2024

Let's make sure the API follows PEP 249 (https://peps.python.org/pep-0249/), preferably so that it's a drop-in replacement for the sqlite3 API in Python: https://docs.python.org/3/library/sqlite3.html

@penberg penberg changed the title feat: setup python binding Initial pass on Python API Aug 6, 2024
@JeanArhancet JeanArhancet force-pushed the feat/impl-python-binding branch 5 times, most recently from 62e914a to 7262dc6 Compare August 9, 2024 10:20
@JeanArhancet
Copy link
Contributor Author

Let's make sure the API follows PEP 249 (https://peps.python.org/pep-0249/), preferably so that it's a drop-in replacement for the sqlite3 API in Python: https://docs.python.org/3/library/sqlite3.html

@penberg I've refactored the code to comply with PEP 249. What do you think?



def test_sqlite3_fetchall_select_all_users():
conn = sqlite3.connect("tests/database.db")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change this now, but you can use @pytest annotation to parametrize a same test case to run with both libraries. See, for example, https://github.com/tursodatabase/libsql-experimental-python/blob/main/tests/test_suite.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@penberg
Copy link
Owner

penberg commented Aug 9, 2024

Looks great @JeanArhancet! All we need to figure out is how to get this to build on Windows... 🙈

/**
* This read/write attribute specifies the number of rows to fetch at a time with .fetchmany().
* It defaults to 1 meaning to fetch a single row at a time.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this is not rustdoc style, see https://doc.rust-lang.org/rust-by-example/meta/doc.html for examples.

@JeanArhancet JeanArhancet force-pushed the feat/impl-python-binding branch 6 times, most recently from 9e21491 to e09ee75 Compare August 11, 2024 06:57
refactor: pep-0249

refactor: rust comment and requirements-dev.txt

fix: name conflict
@penberg penberg merged commit b3d1db3 into penberg:main Aug 11, 2024
13 checks passed
penberg added a commit that referenced this pull request Sep 22, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants