Skip to main content
# ddb-local

Python wrapper for DynamoDB Local.

## What is it for?

This is a convenient Python wrapper for [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html). All the instructions online currently involves manually downloading the tarball and installing it, which is a huge hassle and is a barrier to automation. It wasn't really easy to integrate the local DDB nicely into tests (e.g., pytest) so I wrote this library.

## Prerequisite

You must have `java` in `PATH` or specify `JAVA_HOME`. You need a working Internet connection to download DynamoDBLocal tarball. Optionally, you can get it yourself, and point `unpack_dir` to the root of the unpacked directory.

## Examples

Get a throwaway in-memory DDB for testing:

```python
import boto3
from ddb_local import create_new_inmemory_ddb

with create_new_inmemory_ddb() as local_ddb:
ddb = boto3.client('dynamodb', endpoint_url=local_ddb.endpoint)
```

Use it in a context manager:

```python
import boto3
from ddb_local import LocalDynamoDB

with LocalDynamoDB() as local_ddb:
ddb = boto3.client('dynamodb', endpoint_url=local_ddb.endpoint)

```

Outside a context manager, you can also call `start()` and `stop()` manually. In this case, it's your responsibility to make sure `stop()` is called.

```python
from ddb_local import LocalDynamoDB

db = LocalDynamoDB()
db.start()
print(f"Endpoint is at {db.endpoint}")
db.stop()
```

Example usage with [pytest](https://pytest.org/):

```python
import pytest
from ddb_local import LocalDynamoDB

@pytest.fixture
def local_ddb():
with LocalDynamoDB():
yield ddb

def test_with_local_ddb(local_ddb):
ddb = boto3.client('dynamodb', endpoint_url=local_ddb.endpoint)
# ...
```

Troubleshooting with debug flag:

```python
from ddb_local import LocalDynamoDB

db = LocalDynamoDB(debug=True)
db.start()
# expect stderr/out from DynamoDbLocal
db.stop()
```

## Development

* `make` to run test, coverage and distribution build.
* `make coverage` to run coverage.
* `make test` to run test.
* `pytest` to run test.
* `make clean` to delete all files.
* `make upload` to upload to PyPI.
* Populate `.pypirc` with the API token.

## Support

Support is provided on a best-effort basis.

Create an issue in the [Github repo](https://github.com/wbkang/ddb_local).

Download files

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

Source Distribution

ddb_local-0.1.5.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file ddb_local-0.1.5.tar.gz.

File metadata

  • Download URL: ddb_local-0.1.5.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for ddb_local-0.1.5.tar.gz
Algorithm Hash digest
SHA256 381d735b95c7cf47bb12f9e4155e48f1eba51d854468466d68ba29d182a396f4
MD5 4ffb9c6dec6503debc2b4f959034c79a
BLAKE2b-256 14027ed20d2c5dfac2a8df1415740810aaa847f4a5ca2d4a255c0c1e56b2e0d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page