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
py-data-api is a user-friendly client which supports SQLAlchemy models.
What's AWS Aurora Serverless's Data API?
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html
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
Example
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
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'
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 my_table (name) VALUES ('ken')
result = data_api.execute(insert)
print(result)
# Result(generated_fields=None, number_of_records_updated=1)
query = Query(Users).filter(Users.id == 1)
result = data_api.execute(query)
# SELECT users.id, users.name FROM users WHERE my_table.id = 1
print(result)
# [[1, 'ken']]
result = data_api.execute('select * from users', with_columns=True)
print(result)
# [{'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')
print(result)
# [[1, 'ken'], [2, 'rei'], [3, 'lisa'], [4, 'taro']]
# commit transaction
Features
Implemented
BeginTransaction
- coreCommitTransaction
- coreExecuteStatement
- coreRollbackTransaction
- coreBatchExecuteStatement
- core
Not Implemented
ExecuteSql(Deprecated API)
TODO
- add unittests
- add documents include docstrings
- add simply function client
Related projects
local-data-api
DataAPI Server for local
https://github.com/koxudaxi/local-data-api
Docker Image
https://hub.docker.com/r/koxudaxi/py-data-api
Source Code
https://github.com/koxudaxi/py-data-api
Documentation
https://koxudaxi.github.io/py-data-api
License
py-data-api is released under the MIT License. http://www.opensource.org/licenses/mit-license
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydataapi-0.0.3.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for pydataapi-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b1fcce77be89f2918459688a24ec9c4823a80bf64fb47c0bcfd68bfa0ca9036 |
|
MD5 | 1856b29611a607ba48f56aa06046622b |
|
BLAKE2b-256 | b5a49f21b83fcbc87e2e0e63d3c4da262e5a9ce2f2cfaed7a3b1d22cbc2c3dc7 |