Skip to main content

No project description provided

Project description

ConnectorX status docs

Load data from to , the fastest way.

ConnectorX enables you to load data from databases into Python in the fastest and most memory efficient way.

What you need is one line of code:

import connectorx as cx

cx.read_sql("postgresql://username:password@server:port/database", "SELECT * FROM lineitem")

Optionally, you can accelerate the data loading using parallelism by specifying a partition column.

import connectorx as cx

cx.read_sql("postgresql://username:password@server:port/database", "SELECT * FROM lineitem", partition_on="l_orderkey", partition_num=10)

The function will partition the query by evenly splitting the specified column to the amount of partitions. ConnectorX will assign one thread for each partition to load and write data in parallel. Currently, we support partitioning on integer columns for SPJA queries.

Check out more detailed usage and examples here.

Installation

pip install connectorx

Performance

We compared different solutions in Python that provides the read_sql function, by loading a 10x TPC-H lineitem table (8.6GB) from Postgres into a DataFrame, with 4 cores parallelism.

Time chart, lower is better.

time chart

Memory consumption chart, lower is better.

memory chart

In conclusion, ConnectorX uses up to 3x less memory and 11x less time.

How does ConnectorX achieve a lightening speed while keeping the memory footprint low?

We observe that existing solutions more or less do data copy multiple times when downloading the data. Additionally, implementing a data intensive application in Python brings additional cost.

ConnectorX is written in Rust and follows "zero-copy" principle. This allows it to make full use of the CPU by becoming cache and branch predictor friendly. Moreover, the architecture of ConnectorX ensures the data will be copied exactly once, directly from the source to the destination.

Detailed Usage and Examples

API

connectorx.read_sql(conn: str, query: Union[List[str], str], *, return_type: str = "pandas", protocol: str = "binary", partition_on: Optional[str] = None, partition_range: Optional[Tuple[int, int]] = None, partition_num: Optional[int] = None)

Run the SQL query, download the data from database into a Pandas dataframe.

Parameters

  • conn(str): Connection string uri. Currently only PostgreSQL is supported.
  • query(string or list of string): SQL query or list of SQL queries for fetching data.
  • return_type(string, optional(default "pandas")): The return type of this function. Currently only "pandas" is supported.
  • partition_on(string, optional(default None)): The column to partition the result.
  • partition_range(tuple of int, optional(default None)): The value range of the partition column.
  • partition_num(int, optional(default None)): The number of partitions to generate.

Examples

  • Read a DataFrame from a SQL using a single thread

    import connectorx as cx
    
    postgres_url = "postgresql://username:password@server:port/database"
    query = "SELECT * FROM lineitem"
    
    cx.read_sql(postgres_url, query)
    
  • Read a DataFrame parallelly using 10 threads by automatically partitioning the provided SQL on the partition column (partition_range will be automatically queried if not given)

    import connectorx as cx
    
    postgres_url = "postgresql://username:password@server:port/database"
    query = "SELECT * FROM lineitem"
    
    cx.read_sql(postgres_url, query, partition_on="partition_col", partition_num=10)
    
  • Read a DataFrame parallelly using 2 threads by manually providing two partition SQLs (the schemas of all the query results should be same)

    import connectorx as cx
    
    postgres_url = "postgresql://username:password@server:port/database"
    queries = ["SELECT * FROM lineitem WHERE partition_col <= 10", "SELECT * FROM lineitem WHERE partition_col > 10"]
    
    cx.read_sql(postgres_url, queries)
    

Next Plan

Checkout our discussions to participate in deciding our next plan!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

connectorx-0.1.1-cp39-cp39-win_amd64.whl (1.8 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

connectorx-0.1.1-cp39-cp39-manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9

connectorx-0.1.1-cp39-cp39-macosx_10_15_intel.whl (2.6 MB view hashes)

Uploaded CPython 3.9 macOS 10.15+ intel

connectorx-0.1.1-cp38-cp38-win_amd64.whl (1.8 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

connectorx-0.1.1-cp38-cp38-manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8

connectorx-0.1.1-cp38-cp38-macosx_10_15_intel.whl (2.6 MB view hashes)

Uploaded CPython 3.8 macOS 10.15+ intel

connectorx-0.1.1-cp37-cp37m-win_amd64.whl (1.8 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

connectorx-0.1.1-cp37-cp37m-manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.7m

connectorx-0.1.1-cp37-cp37m-macosx_10_15_intel.whl (2.6 MB view hashes)

Uploaded CPython 3.7m macOS 10.15+ intel

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page