Amazon QLDB Driver for Python - Amazon Quantum Ledger Database (Amazon QLDB)

Amazon QLDB Driver for Python

To work with data in your ledger, you can connect to Amazon QLDB from your Python application by using an AWS-provided driver. The following sections describe how to get started with the QLDB Driver for Python.

Driver Resources

For more information about the functionality supported by the Python driver, see the following resources:

Prerequisites

Before you get started with the QLDB Driver for Python, you must do the following:

  1. Follow the AWS setup instructions in Accessing Amazon QLDB. This includes signing up for AWS and getting an AWS access key for development.

  2. Install Python version 3.4 or later from the Python downloads site.

  3. Set up your AWS credentials and your default AWS Region. For instructions, see Quickstart in the AWS SDK for Python (Boto3) documentation.

    For a complete list of available Regions, see Amazon QLDB Endpoints and Quotas in the AWS General Reference.

Next, you can download the complete tutorial sample application—or you can install only the driver in an existing Python project.

  • To run the complete tutorial with the QLDB sample application, see the Python Tutorial.

  • To install only the QLDB Driver and the AWS SDK for Python (Boto3) in an existing project, proceed to Installation (Driver Only).

Installation (Driver Only)

QLDB supports the following driver versions and their Python dependencies.

Driver version Python version Status Latest release date
2.x 3.4 or later Production release May 7, 2020
3.0.0rc1 3.6 or later Release candidate June 22, 2020

To install the QLDB Driver from PyPI using pip (a package manager for Python), enter the following at the command line.

2.x
pip install pyqldb==2.0.2
3.0.0rc1
Warning

This version of the driver is a release candidate. It is subject to change and might not be production ready.

pip install pyqldb==3.0.0rc1

Installing the driver also installs its dependencies, including the AWS SDK for Python (Boto3) and Amazon Ion packages.

Using the driver to connect to a ledger

Then you can import the driver and use it to connect to a ledger. The following Python code example shows how to create a session for a specified ledger name.

2.x
from pyqldb.driver.pooled_qldb_driver import PooledQldbDriver qldb_driver = PooledQldbDriver(ledger_name='testLedger') qldb_session = qldb_driver.get_session() for table in qldb_session.list_tables(): print(table)
3.0.0rc1
from pyqldb.driver.qldb_driver import QldbDriver qldb_driver = QldbDriver(ledger_name='testLedger') for table in qldb_driver.list_tables(): print(table)

For short code examples of how to run basic data transactions on a ledger, proceed to the Cookbook reference. For more in-depth examples that demonstrate both data and control plane operations in a full sample application, see the Python Tutorial.