Skip to main content
https://raw.githubusercontent.com/dbfixtures/pytest-dynamodb/master/logo.png

pytest-dynamodb

Latest PyPI version Wheel Status Supported Python Versions License

DynamoDB fixtures for pytest.

What is this?

pytest-dynamodb is a pytest plugin for tests that need a running DynamoDB instance. It provides fixtures for both a managed local process and a connection to an already running instance.

Project Architecture Diagram

Quickstart: first test

  1. Install the plugin and your test dependencies.

  2. Download and unpack DynamoDB Local (see AWS docs): https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html Place extracted files in dynamodb_dir (default: /tmp/dynamodb), or choose another location and pass it via --dynamodb-dir when running tests.

  3. Make sure Java is available in your environment (DynamoDB Local runs as a JAR).

  4. Write a test that uses the built-in dynamodb fixture:

import uuid

def test_can_put_and_get_item(dynamodb):
    table = dynamodb.create_table(
        TableName="Test",
        KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}],
        AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}],
        ProvisionedThroughput={"ReadCapacityUnits": 10, "WriteCapacityUnits": 10},
    )

    _id = str(uuid.uuid4())
    table.put_item(Item={"id": _id, "test_key": "test_value"})
    item = table.get_item(Key={"id": _id})

    assert item["Item"]["test_key"] == "test_value"
  1. Run tests:

pytest

For a full example, see tests/test_dynamodb.py.

How to use

The plugin contains three fixtures:

  • dynamodb - function-scoped DynamoDBServiceResource fixture.

  • dynamodb_proc - session-scoped fixture that starts DynamoDB Local on first use and stops it at the end of the test session.

  • dynamodb_noproc - session-scoped fixture that connects to an externally managed DynamoDB instance (for example, Docker).

When to use which fixture:

  • Use dynamodb (default) when tests should manage a local process automatically.

  • Use dynamodb_noproc when DynamoDB is already running elsewhere and lifecycle is managed outside pytest.

Simply include one of these fixtures in your test fixture list.

You can also create additional client and process fixtures:

from pytest_dynamodb import factories

dynamodb_my_proc = factories.dynamodb_proc(port=None, delay=True)
dynamodb_my = factories.dynamodb("dynamodb_my_proc")
from pytest_dynamodb import factories

dynamodb_my_noproc = factories.dynamodb_noproc(host="dynamodb", port=8088)
dynamodb_my = factories.dynamodb("dynamodb_my_noproc")

Configuration

You can define settings in three ways:

  • Fixture factory argument

  • Command line option

  • Configuration option in pytest.ini

Precedence order:

  • Fixture factory argument

  • Command line option

  • pytest.ini option

Configuration options

DynamoDB option

Fixture factory argument

Command line option

pytest.ini option

Default

Path to DynamoDB JAR directory

dynamodb_dir

–dynamodb-dir

dynamodb_dir

/tmp/dynamodb

Host

host

–dynamodb-host

dynamodb_host

127.0.0.1

Port

port

–dynamodb-port

dynamodb_port

random

AWS Access Key

access_key

–dynamodb-aws_access_key

dynamodb_aws_access_key

fakeMyKeyId

AWS Secret Key

secret_key

–dynamodb-aws_secret_key

dynamodb_aws_secret_key

fakeSecretAccessKey

AWS Region

region

–dynamodb-aws_region

dynamodb_aws_region

us-west-1

Introduce delays

delay

–dynamodb-delay

dynamodb_delay

false

Example usage:

  • Pass as fixture factory argument:

    from pytest_dynamodb import factories
    
    dynamodb_proc = factories.dynamodb_proc(port=8888)
  • Use command line option:

    pytest tests --dynamodb-port=8888
  • Set in pytest.ini:

    [pytest]
    dynamodb_port = 8888

Known issues

  • Parallel runs with a fixed --dynamodb-port may fail because workers contend for the same port.

Package resources

Release files for pytest-dynamodb 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-dynamodb 3.0.1
File Size Uploaded
pytest_dynamodb-3.0.1.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-dynamodb 3.0.1
File Interpreter ABI Platform
pytest_dynamodb-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.4 kB

Release files / pytest_dynamodb-3.0.1.tar.gz

Download URL pytest_dynamodb-3.0.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d95f6b8f0feccd57162decc75a1ed1d84445e3a8d340a839cfc356e912ce10c4
BLAKE2b-256 checksum
How to use checksums
d148269a4a24d9a5ebd52d877d304328d94af71133d68f456f184fb476c3f026
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / pytest_dynamodb-3.0.1-py3-none-any.whl

Download URL pytest_dynamodb-3.0.1-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f02a763c8ed689838d19d857424e1b14b19da04ee1ee2cfb270e207444c76c2
BLAKE2b-256 checksum
How to use checksums
76de1453189e55c844441d4398d710db2b8357a2b1a004ec36061cb799a62e99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

1 release file

2.0.0

1 release file

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.0

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