Python DB API 2.0 (PEP 249) client for Amazon DynamoDB
Project description
PyDynamoDB
PyDynamoDB is a Python DB API 2.0 (PEP 249) client for Amazon DynamoDB. SQLAlchemy dialect supported as well.
Objectives
PyDynamoDB implement the DB API 2.0 interfaces based on PartiQL supported by AWS DynamoDB. Although PartiQL can only support DML operations (INSERT, UPDATE, DELETE, SELECT), PyDynamoDB extended the capabilities to support DDL as well. Now you are able to use MySQL-like statements to CREATE/ALTER/DROP tables. Besides DDL statements, some of utility statements are allowed to execute (Such as, List and Describe Table). PyDynamodb provide parameters and result_set converter to make you easily manipulate operations with Python built-in types. Transaction is also partially supported with DB standard operations, like begin() and commit().
Features
Compatible with DB API 2.0 Specification
PartiQL for DML operations (INSERT, UPDATE, DELETE, SELECT)
Limit supported in SELECT statement
Extra type conversion and string functions supported in SELECT statement
Column alias supported in SELECT statement
MySQL-Like statements for DDL operations (CREATE TABLE, ALTER TABLE, DROP TABLE)
MySQL-Like statements for Utility operations (LIST/SHOW TABLES, DESC TABLE)
Auto data type conversion for parameters and result set (Including date and datetime)
Transaction and Batch operations
SQLAlchemy dialect provided
Compatible for Superset SQL Lab and graphing
Requirements
Python
CPython 3.8 3.9 3.10 3.11 3.12
Dependencies
Boto3 (Python SDK for AWS Services)
boto3 >= 1.21.0
botocore >= 1.24.7
Tenacity (Retry Utility for API calling)
tenacity >= 4.1.0
SQLAlchemy (The ORM Toolkit for Python, only required if using PyDynamoDB Dialect)
SQLAlchemy >= 1.0.0
Pyparsing (The approach to creating and executing simple grammars)
pyparsing >= 3.0.0
Installation
pip install pydynamodb
Guidances
To get more documentation, please visit: PyDynamoDB WIKI.
Basic usage
from pydynamodb import connect
cursor = connect(aws_access_key_id="aws_access_key_id",
aws_secret_access_key="aws_secret_access_key",
region_name="region_name").cursor()
cursor.execute('SELECT * FROM "ddb_table_name"')
print(cursor.fetchall())
Cursor iteration
from pydynamodb import connect
cursor = connect(aws_access_key_id="aws_access_key_id",
aws_secret_access_key="aws_secret_access_key",
region_name="region_name").cursor()
cursor.execute('SELECT * FROM "ddb_table_name"')
rows = cursor.fetchall()
for row in rows:
print(row)
Query with parameters
PyDynamoDB is able to serialize the parameters which passed to DDB and deserialize the response to Python built-in types.
from pydynamodb import connect
from datetime import date, datetime
cursor = connect(aws_access_key_id="aws_access_key_id",
aws_secret_access_key="aws_secret_access_key",
region_name="region_name").cursor()
cursor.execute("""INSERT INTO "ddb_table_name" VALUE {
'partition_key' = ?, 'sort_key' = ?, 'col_str' = ?,
'col_num' = ?, 'col_byte' = ?, 'col_ss' = ?,
'col_ns' = ?, 'col_bs' = ?, 'col_list' = ?,
'col_map' = ?, 'col_nested' = ?,
'col_date' = ?, 'col_datetime' = ?
}""", ["pkey_value", "skey_value", "str", 100, b"ABC", # String, Number, Bytes
{"str", "str"}, {100, 100}, {b"A", b"B"}, # String/Numnber/Bytes Set
["str", 100, b"ABC"], # List
{"key1": "val", "key2": "val"}, # Map
["str", 100, {"key1": "val"}], # Nested Structure
date(2022, 10, 18), datetime(2022, 10, 18, 13, 55, 34), # Date and Datetime Type
])
cursor.execute('SELECT * FROM "ddb_table_name" WHERE partition_key = ?', ["key_value"])
print(cursor.fetchall())
License
PyDynamoDB is distributed under the 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
Built Distribution
File details
Details for the file PyDynamoDB-0.7.1.tar.gz
.
File metadata
- Download URL: PyDynamoDB-0.7.1.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95615a0ecb8c9a071f138cafd1f976e78d071b0f9a7f5105b9a4f11880c1b6bf |
|
MD5 | 03d5fe1dbc68891042d3ed1b25ea31e7 |
|
BLAKE2b-256 | d48febb339cd3e801a5f8002fd3c4ba19ac82750d8ea7990411eb0ef7ab5eace |
File details
Details for the file PyDynamoDB-0.7.1-py3-none-any.whl
.
File metadata
- Download URL: PyDynamoDB-0.7.1-py3-none-any.whl
- Upload date:
- Size: 57.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cf70cce15d9e83e153d49d02b4757fecdc6bf613b4dfca75439c7efc4ba1b7a |
|
MD5 | ebb50cccceb0e5b969cafde4efd99080 |
|
BLAKE2b-256 | 7990e43ac9a7868f2eaac29b98c05d45ef79d1d985ba08da7db2e3fd1a658b78 |