Skip to main content
https://badge.fury.io/py/pydynamodb.svg https://github.com/passren/PyDynamoDB/actions/workflows/run-test.yaml/badge.svg https://static.pepy.tech/badge/pydynamodb/month https://img.shields.io/badge/code%20style-black-000000.svg https://codecov.io/github/passren/PyDynamoDB/branch/main/graph/badge.svg?token=Y5DG320O76

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 functions (DATE, DATETIME, NUMBER, BOOL) 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.7 3.8 3.9 3.10

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, < 2.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.

Download files

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

Source Distribution

PyDynamoDB-0.5.2.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyDynamoDB-0.5.2-py3-none-any.whl (52.2 kB view details)

Uploaded Python 3

File details

Details for the file PyDynamoDB-0.5.2.tar.gz.

File metadata

  • Download URL: PyDynamoDB-0.5.2.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for PyDynamoDB-0.5.2.tar.gz
Algorithm Hash digest
SHA256 b9879a653db193c8bd86322c33132245ac84f79c23fecf911383f1700ed6bdc3
MD5 a75a0aa66fcdbe06abe9f4e38c9629a0
BLAKE2b-256 f8aa43a944463f24d045c2346e4ec57751d9f077ec593737c1da16ed093dfea2

See more details on using hashes here.

File details

Details for the file PyDynamoDB-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: PyDynamoDB-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 52.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for PyDynamoDB-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 457112316ebf107bab0a73ab4fc698d4197dc100a57e369ca801d8a86a7a8991
MD5 ac3fcd0b972ec290714d7b9829915a53
BLAKE2b-256 ca41674be99c7b05bf0a7ede633770480988e9698de377683be79e77a2076db2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.8

2 files

0.5.7

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

This release

0.5.2 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page