Metadata-Version: 2.1
Name: peaka
Version: 1.0.0
Summary: A Python client for Peaka
Home-page: https://peaka.com/docs/python-client
Author: Peaka
Author-email: integrations@peaka.com
Keywords: data,peaka
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Database :: Front-Ends
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: trino
Requires-Dist: SQLAlchemy
Provides-Extra: dev
Requires-Dist: check-manifest; extra == "dev"
Requires-Dist: pydoc-markdown; extra == "dev"
Requires-Dist: novella; extra == "dev"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"

# Peaka Python client

Client for [Peaka](https://peaka.com/), a Zero-ETL data integration platform. 
Provides a low-level client and a DBAPI 2.0 implementation and a SQLAlchemy adapter.
It supports Python>=3.8 and PyPy.

## Usage

### The Python Database API (DBAPI)

**Installation**

```
$ pip install peaka
```

**Quick Start**

Use the DBAPI interface to query Peaka:

You can call the `connect_to_peaka` method with your Peaka `api_key`. `catalog`, `schema` and `timezone` are the optional parameters.

```python
from peaka.client import connect_to_peaka

conn = connect_to_peaka(api_key="<YOUR_API_KEY>", catalog="<CATALOG_NAME>", schema="<SCHEMA_NAME>", timezone="<TIMEZONE>")
    
cur = conn.cursor()
cur.execute("SELECT * FROM <table_name>")
rows = cur.fetchall()
```

You can query your `table` directly, if you enter the `catalog` and `schema` when you connect.

### SQLAlchemy

**Installation**

```
$ pip install peaka[sqlalchemy]
```

**Usage**

To connect to Peaka using SQLAlchemy, use a connection string (URL) following this pattern:

```
peaka://dbc.peaka.studio:4567/<catalog>/<schema>?http_scheme=https&extra_credential=[["peakaKey",<YOUR_API_KEY>]]&access_token=true
```

NOTE: `schema` is optional

**Examples**:

```python
from sqlalchemy import create_engine
from sqlalchemy.schema import Table, MetaData
from sqlalchemy.sql.expression import select, text

engine = create_engine('peaka://dbc.peaka.studio:4567/<CATALOG_NAME>/<SCHEMA_NAME>?http_scheme=https&extra_credential=[["peakaKey",<YOUR_API_KEY>]]&access_token=true')
connection = engine.connect()

rows = connection.execute(text("SELECT * FROM <TABLE_NAME>")).fetchall()

# or using SQLAlchemy schema
nodes = Table(
    '<TABLE_NAME>',
    MetaData(schema='<SCHEMA_NAME>'),
    peaka_autoload=True,
    autoload_with=engine
)
rows = connection.execute(select(nodes)).fetchall()
```

In order to pass additional connection attributes use [connect_args](https://docs.sqlalchemy.org/en/14/core/engines.html#sqlalchemy.create_engine.params.connect_args) method.
Attributes can also be passed in the connection string.
