Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

py-data-api is a user-friendly client for AWS Aurora Serverless's Data API

Project description

py-data-api - Data API Client for Python

Build Status PyPI version codecov

py-data-api is a user-friendly client which supports SQLAlchemy models.

What's AWS Aurora Serverless's Data API?

This project is an experimental phase.

Warning: Some interface will be changed.

How to install

pydataapi requires Python 3.7.0 or later

$ pip install pydataapi


from typing import List

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Query
from sqlalchemy.sql import Insert

from pydataapi import DataAPI, transaction

class Users(declarative_base()):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(255, collation='utf8_unicode_ci'), default=None)

database: str = 'test'
resource_arn: str = 'arn:aws:rds:us-east-1:123456789012:cluster:serverless-test-1'
secret_arn: str = 'arn:aws:secretsmanager:us-east-1:123456789012:secret:serverless-test1'

@transaction(database=database, resource_arn=resource_arn, secret_arn=secret_arn)
def add_users(data_api: DataAPI, user_names: List[str]) -> None:
    # start transaction
    for user_name in user_names:
        data_api.execute(Insert(Users, {'name': user_name}))
        # some logic ...

    # commit

def example_simple_execute():
    data_api = DataAPI(resource_arn, secret_arn, database=database)
    result = data_api.execute('show tables')
    # [[Persons, Users, Pets]]

def example_decorator():
    user_names: List[str] = ['ken', 'rei', 'lisa', 'taro']

def example_with_statement():
    with DataAPI(database=database, resource_arn=resource_arn, secret_arn=secret_arn) as data_api:

        # start transaction

        insert: Insert = Insert(Users, {'name': 'ken'})
        # INSERT INTO users (name) VALUES ('ken')

        result = data_api.execute(insert)
        # [Result(generated_fields=None, number_of_records_updated=1)]

        query = Query(Users).filter( == 1)
        result = data_api.execute(query)
        # SELECT, FROM users WHERE = 1

        # [[1, 'ken']]

        result = data_api.execute('select * from users', with_columns=True)
        # [{'id': 1, 'name': 'ken'}]

        # batch insert
        insert: Insert = Insert(Users)
        data_api.execute(insert, [
            {'id': 2, 'name': 'rei'},
            {'id': 3, 'name': 'lisa'},
            {'id': 4, 'name': 'taro'},

        result = data_api.execute('select * from users')
        # [[1, 'ken'], [2, 'rei'], [3, 'lisa'], [4, 'taro']]

        # commit

def example_rollback():
    with DataAPI(resource_arn, secret_arn) as data_api:
        data_api.execute(Insert(Users, {'name': 'ken'}))
        # you can rollback by Exception
        raise Exception

def example_rollback_with_custom_exception():
    class OriginalError(Exception):

    with DataAPI(resource_arn, secret_arn, rollback_exception=OriginalError) as data_api:

        data_api.execute(Insert(Users, {'name': 'ken'}))
        # some logic ...

        # rollback when happen `rollback_exception`
        raise OriginalError  # rollback

        # raise Exception <- DataAPI don't rollback



  • BeginTransaction - core
  • CommitTransaction - core
  • ExecuteStatement - core
  • RollbackTransaction - core
  • BatchExecuteStatement - core

Not Implemented

  • ExecuteSql(Deprecated API)


  • add unittests
  • add documents include docstrings
  • add simply function client

Related projects


DataAPI Server for local


Source Code



py-data-api is released under the MIT License.

Project details

Download files

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

Files for pydataapi, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size pydataapi-0.1.1-py3-none-any.whl (8.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pydataapi-0.1.1.tar.gz (6.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page