Skip to content

Commit 5a34212

Browse files
author
Janos Tolgyesi
committed
Completing documentation
1 parent 5e6b70f commit 5a34212

File tree

10 files changed

+229
-235
lines changed

10 files changed

+229
-235
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ coverage: ## check code coverage quickly with the default Python
6767
$(BROWSER) htmlcov/index.html
6868

6969
docs: ## generate Sphinx HTML documentation, including API docs
70-
rm -f docs/dynamodb_mapping.rst
71-
rm -f docs/modules.rst
72-
sphinx-apidoc -o docs/ dynamodb_mapping
70+
# rm -f docs/dynamodb_mapping.rst
71+
# rm -f docs/modules.rst
72+
# sphinx-apidoc -o docs/ dynamodb_mapping
7373
$(MAKE) -C docs clean
7474
$(MAKE) -C docs html
7575
$(BROWSER) docs/_build/html/index.html

README.rst

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,134 @@ DynamoDB Mapping
2222

2323
A Python dictionary-like interface for an Amazon DynamoDB table.
2424

25+
DynamoDBMapping is an alternative API for `Amazon DynamoDB`_ that implements the Python
26+
``collections.abc.MutableMapping`` abstract base class, effectively allowing you to use a DynamoDB
27+
table as if it were a Python dictionary.
2528

2629
* Free software: MIT license
2730
* Documentation: https://dynamodb-mapping.readthedocs.io.
2831

32+
.. _Amazon DynamoDB: https://aws.amazon.com/dynamodb/
2933

30-
Features
31-
--------
3234

33-
* A Python dictionary-like interface for an Amazon DynamoDB table.
35+
Getting started
36+
---------------
37+
38+
To do anything useful with this module you need an Amazon Web Services account and an Amazon
39+
DynamoDB table. In every AWS account several DynamoDB tables can be created for free. Open
40+
an `AWS account`_ and `create a DynamoDB table`_. You also need to create a IAM user and configure
41+
the access keys on your workstation. The easiest way to do so is to install and configure the
42+
`AWS Command Line Interface`_. Once the AWS CLI works correctly, the AWS Python libraries (boto3)
43+
will correctly pick up the credentials.
44+
45+
.. _AWS account: https://aws.amazon.com/free/
46+
.. _create a DynamoDB table: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/getting-started-step-1.html
47+
.. _AWS Command Line Interface: https://docs.aws.amazon.com/cli/index.html
48+
49+
50+
Installation
51+
------------
52+
53+
Stable release
54+
~~~~~~~~~~~~~~
55+
56+
To install DynamoDB Mapping, run this command in your terminal:
57+
58+
.. code-block:: console
59+
60+
$ pip install dynamodb_mapping
61+
62+
This is the preferred method to install DynamoDB Mapping, as it will always install the most recent stable release.
63+
64+
If you don't have `pip`_ installed, this `Python installation guide`_ can guide
65+
you through the process.
66+
67+
.. _pip: https://pip.pypa.io
68+
.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
69+
70+
71+
From sources
72+
~~~~~~~~~~~~
73+
74+
The sources for DynamoDB Mapping can be downloaded from the `Github repo`_.
75+
76+
You can either clone the public repository:
77+
78+
.. code-block:: console
79+
80+
$ git clone git://github.com/mrtj/dynamodb_mapping
81+
82+
Or download the `tarball`_:
83+
84+
.. code-block:: console
85+
86+
$ curl -OJL https://github.com/mrtj/dynamodb_mapping/tarball/master
87+
88+
Once you have a copy of the source, you can install it with:
89+
90+
.. code-block:: console
91+
92+
$ python setup.py install
93+
94+
95+
.. _Github repo: https://github.com/mrtj/dynamodb_mapping
96+
.. _tarball: https://github.com/mrtj/dynamodb_mapping/tarball/master
97+
98+
99+
Usage
100+
-----
101+
102+
Once the credentials are correctly configured, you can start reading and writing to your DynamoDB
103+
table with DynamoDBMapping as it was an ordinal Python dictionary::
104+
105+
from dynamodb_mapping import DynamoDBMapping
106+
107+
mapping = DynamoDBMapping(table_name="my_table")
108+
109+
# Create or modify an item:
110+
mapping["my_item"] = {"description": "foo", "price": 123}
111+
mapping["my_item"]["price"] = 456
112+
113+
# Iterate over all items:
114+
for key, value in mapping.items():
115+
print(key, value)
116+
117+
# Get a single item:
118+
print(mapping["my_item"])
119+
120+
# Number of items in table:
121+
# (read bellow on how to get the estimated vs precise number of items)
122+
print(len(mapping))
123+
124+
# Delete an item:
125+
del mapping["my_item"]
126+
127+
128+
All methods that iterate over the elements of the table do so in a lazy manner, in that the
129+
successive pages of the scan operation are queried only on demand. Examples of such operations
130+
include scan, iteration over keys, iteration over values, and iteration over items (key-value
131+
tuples). You should pay particular attention to certain patterns that fetch all items in the table,
132+
for example, calling ``list(mapping.values())``. This call will execute an exhaustive scan on your
133+
table, which can be costly, and attempt to load all items into memory, which can be
134+
resource-demanding if your table is particularly large.
135+
136+
The ``__len__`` implementation of this class returns a best-effort estimate of the number of items
137+
in the table using the TableDescription DynamoDB API. The number of items are updated at DynamoDB
138+
service side approximately once in every 6 hours. If you need the exact number of items currently in
139+
the table, you can use ``len(list(mapping.keys()))``. Note however that this will cause to run an
140+
exhaustive scan operation on your table.
141+
142+
143+
Advanced configuration
144+
----------------------
145+
146+
You have the following options to configure the underlying boto3 session:
147+
148+
- Automatic configuration: pass nothing to DynamoDBMapping initializer. This will prompt
149+
DynamoDBMapping to load the default ``boto3.Session`` object, which in turn will use the
150+
standard boto3 credentials chain to find AWS credentials (e.g., the ``~/.aws/credentials``
151+
file, environment variables, etc.).
152+
- Pass a preconfigured ``boto3.Session`` object
153+
- Pass ``aws_access_key_id`` and ``aws_secret_access_key`` as keyword arguments. Additionally,
154+
the optional ``aws_region`` and ``aws_profile`` arguments are also considered.
155+

docs/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,8 @@
179179
'boto3': ('https://boto3.amazonaws.com/v1/documentation/api/latest/', None),
180180
'botocore': ('https://botocore.readthedocs.io/en/latest/', None),
181181
}
182+
183+
autodoc_type_aliases = {
184+
'DynamoDBItemType': 'DynamoDBItemType',
185+
'DynamoDBKeySimplified': 'DynamoDBKeySimplified',
186+
}

docs/dynamodb_mapping.rst

Lines changed: 0 additions & 21 deletions
This file was deleted.

docs/index.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
Welcome to DynamoDB Mapping's documentation!
2-
======================================
2+
============================================
33

44
.. toctree::
55
:maxdepth: 2
66
:caption: Contents:
77

88
readme
9-
installation
10-
usage
119
modules
1210
contributing
1311
authors

docs/installation.rst

Lines changed: 0 additions & 51 deletions
This file was deleted.

docs/modules.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
dynamodb_mapping
2-
================
1+
API Documentation
2+
=================
33

4-
.. toctree::
5-
:maxdepth: 4
6-
7-
dynamodb_mapping
4+
.. automodule:: dynamodb_mapping
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:special-members: DynamoDBKeySimplified, DynamoDBItemType

docs/usage.rst

Lines changed: 0 additions & 83 deletions
This file was deleted.

dynamodb_mapping/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Top-level package for DynamoDB Mapping."""
22

3-
from .dynamodb_mapping import DynamoDBMapping
3+
from __future__ import annotations
4+
5+
from .dynamodb_mapping import DynamoDBMapping, DynamoDBKeySimplified, DynamoDBItemType
46

57
__author__ = """Janos Tolgyesi"""
68
__email__ = 'janos.tolgyesi@gmail.com'
79
__version__ = '0.1.0'
8-
__all__ = ['DynamoDBMapping']
10+
__all__ = ['DynamoDBMapping', 'DynamoDBKeySimplified', 'DynamoDBItemType']

0 commit comments

Comments
 (0)