pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.73k stars 17.95k forks source link

ENH: Load SQL engine backends via `entrypoints` #41728

Open yehoshuadimarsky opened 3 years ago

yehoshuadimarsky commented 3 years ago

Follow up to #36893. Per @xhochy's suggestion we should use entrypoints as a mechanism for loading alternate SQL engine backends, similar to what we do with plotting backends. Creating a new issue for it per the comment here.

yehoshuadimarsky commented 3 years ago

@xhochy can you please clarify for me, in this scenario that we will load SQL engine backends via entrypoints, what exactly does the SQL backend library need to provide to be compatible? I see you wrote here that it needs to add this to its setup.{py|cfg}

entry_points={"pandas_sql_engine": ["turbodbc = turbodbc.TurbodbcPandasEngine"]}

but what does turbodbc.TurbodbcPandasEngine actually need to implement?

yehoshuadimarsky commented 3 years ago

Actually some good reading here:

Appears that the group portion should be delimited by dots, not underscores, e.g.

entry_points={"pandas.sql.engine": ["turbodbc = turbodbc.TurbodbcPandasEngine"]}
yehoshuadimarsky commented 3 years ago

Looking around, we can potentially reuse some of the plugin approaches that other popular libraries use. Some examples that come to mind:

Pytest

yehoshuadimarsky commented 3 years ago

And maybe we should centralize all plugin loading into a single module with common functions, and that can be invoked from the specific places that need it like plotting, sql engine, etc. Would make adding more plugins easier

jreback commented 3 years ago

happy to get something to work then move to a more formal plugin structure

yehoshuadimarsky commented 3 years ago

Sounds good, working on it. @xhochy how do we enforce that the sql engine has the correct interface? Or do we not do so, we just let the user select an engine and it's up to the engine library to create a function that has the correct signature, and if it fails, it fails? Should an engine library import the base abstract SqlEngine class to subclass from, or is that too strong of a dependency?

Trying to understand what the expectations are for these kinds of loosly coupled dependencies...

yehoshuadimarsky commented 3 years ago

take

yehoshuadimarsky commented 3 years ago

Sounds good, working on it. @xhochy how do we enforce that the sql engine has the correct interface? Or do we not do so, we just let the user select an engine and it's up to the engine library to create a function that has the correct signature, and if it fails, it fails? Should an engine library import the base abstract SqlEngine class to subclass from, or is that too strong of a dependency?

Trying to understand what the expectations are for these kinds of loosly coupled dependencies...

@xhochy surfacing this again, are you able to provide some guidance around this?