Package: chdb
chDB中文chDB is an embedded SQL OLAP Engine powered by ClickHouse  [^1]
For more details:The birth of chDBFeaturesIn-process SQL OLAP Engine, powered by ClickHouseNo need to install ClickHouseMinimized data copy from C++ to Python withpython memoryviewInput&Output support Parquet, CSV, JSON, Arrow, ORC and 60+moreformats,samplesSupport Python DB API 2.0,exampleArchGet StartedGet started withchdbusing ourInstallation and Usage ExamplesInstallationCurrently, chDB supports Python 3.8+ on macOS and Linux (x86_64 and ARM64).pipinstallchdbUsageRun in command linepython3 -m chdb SQL [OutputFormat]python3-mchdb"SELECT 1,'abc'"PrettyData InputThe following methods are available to access on-disk and in-memory data formats:🗂️ Query On File(Parquet, CSV, JSON, Arrow, ORC and 60+)You can execute SQL and return desired format data.importchdbres=chdb.query('select version()','Pretty');print(res)Work with Parquet or CSV# See more data type format in tests/format_output.pyres=chdb.query('select * from file("data.parquet", Parquet)','JSON');print(res)res=chdb.query('select * from file("data.csv", CSV)','CSV');print(res)print(f"SQL read{res.rows_read()}rows,{res.bytes_read()}bytes, elapsed{res.elapsed()}seconds")Pandas dataframe output# See more in https://clickhouse.com/docs/en/interfaces/formatschdb.query('select * from file("data.parquet", Parquet)','Dataframe')🗂️ Query On Table(Pandas DataFrame, Parquet file/bytes, Arrow bytes)Query On Pandas DataFrameimportchdb.dataframeascdfimportpandasaspd# Join 2 DataFramesdf1=pd.DataFrame({'a':[1,2,3],'b':["one","two","three"]})df2=pd.DataFrame({'c':[1,2,3],'d':["①","②","③"]})ret_tbl=cdf.query(sql="select * from __tbl1__ t1 join __tbl2__ t2 on t1.a = t2.c",tbl1=df1,tbl2=df2)print(ret_tbl)# Query on the DataFrame Tableprint(ret_tbl.query('select b, sum(a) from __table__ group by b'))🗂️ Query with Stateful Sessionfromchdbimportsessionaschs## Create DB, Table, View in temp session, auto cleanup when session is deleted.sess=chs.Session()sess.query("CREATE DATABASE IF NOT EXISTS db_xxx ENGINE = Atomic")sess.query("CREATE TABLE IF NOT EXISTS db_xxx.log_table_xxx (x String, y Int) ENGINE = Log;")sess.query("INSERT INTO db_xxx.log_table_xxx VALUES ('a', 1), ('b', 3), ('c', 2), ('d', 5);")sess.query("CREATE VIEW db_xxx.view_xxx AS SELECT * FROM db_xxx.log_table_xxx LIMIT 4;")print("Select from view:\n")print(sess.query("SELECT * FROM db_xxx.view_xxx","Pretty"))see also:test_stateful.py.🗂️ Query with Python DB-API 2.0importchdb.dbapiasdbapiprint("chdb driver version:{0}".format(dbapi.get_client_info()))conn1=dbapi.connect()cur1=conn1.cursor()cur1.execute('select version()')print("description: ",cur1.description)print("data: ",cur1.fetchone())cur1.close()conn1.close()🗂️ Query with UDF (User Defined Functions)fromchdb.udfimportchdb_udffromchdbimportquery@chdb_udf()defsum_udf(lhs,rhs):returnint(lhs)+int(rhs)print(query("select sum_udf(12,22)"))see also:test_udf.py.For more examples, seeexamplesandtests.Demos and ExamplesProject DocumentationandUsage ExamplesColab Notebooksand otherScript ExamplesBenchmarkClickBench of embedded enginesDocumentationFor chdb specific examples and documentation refer todoc.chdb.ioFor SQL syntax, please refer toClickHouse SQL ReferenceEventsDemo chDB atClickHouse v23.7 livehouse!andSlidesContributingContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make aregreatly appreciated.
There are something you can help:Help test and report bugsHelp improve documentationHelp improve code quality and performanceBindingsWe welcome bindings for other languages, please refer tobindingsfor more details.LicenseApache 2.0, seeLICENSEfor more information.AcknowledgmentschDB is mainly based onClickHouse[^1]
for trade mark and other reasons, I named it chDB.ContactDiscord:https://discord.gg/D2Daa2fM5KEmail:auxtenwpc@gmail.comTwitter:@chdb[^1]: ClickHouse® is a trademark of ClickHouse Inc. All trademarks, service marks, and logos mentioned or depicted are the property of their respective owners. The use of any third-party trademarks, brand names, product names, and company names does not imply endorsement, affiliation, or association with the respective owners.