dynamo-dictionary

Easily Use DynamoDB as a key-value format.


License
MIT
Install
pip install dynamo-dictionary==1.0.1

Documentation

Project logo

Dynamo Dictionary

Status GitHub Issues GitHub Pull Requests License


Easily Use DynamoDB as a key-value format.

📝 Table of Contents

🧐 About

Easily Use DynamoDB as a key-value format. You can use following functions.

🏁 Getting Started

Installing

pip install dynamo_dictionary

Prerequisites

1. Access Key required for DynamoDB Authentication. If you don't have Access Key, Please follow below steps.

  1. Click below URL.

    https://console.aws.amazon.com/iam/home#/users

  2. Click Add user button.

    add-user-1

  3. Input User name and enable Programmatic access.

    add-user-2

  4. Click Attach existing policies directly and Search S3FullAccess and check AmazonS3FullAccess and click Next:Tags.

    add-user-3

  5. Click Next:Review

    add-user-4

  6. click Create user add-user-5

  7. copy Access Key ID and Secret access Key to user notepad.

    add-user-6

  8. complete!

3. You need to know which region your dynamodb table is in. If you don't know yet, Please refer to URL below.

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/using-regions-availability-zones.html

3. (Required) Create Handler

Use this code to create handler.

import dynamo_dictionary

table_name = "Your Table Name"
region_name = "Your Region Name"

# You don't need to use these two parameters if your authentication file is in ~/.aws/config.
aws_access_key_id = "YOUR AWS ACCESS KEY ID"
aws_secret_access_key = "YOUR AWS SECRET ACCESS KEY"

handler = dynamo_dictionary.DynamoDictionary(table_name, region_name,
                    aws_access_key_id=aws_access_key_id,
                    aws_secret_access_key=aws_secret_access_key)

print(handler)

result:

waiting for create table. . .
<dynamo_dictionary.DynamoDictionary object at 0x0136E448>

🎈 Usage

Please check Prerequisites before starting Usage.

🌱 Put

Use this function to save data into DynamoDB Table.

Examples

>>> print(handler.put("fruit", {"name": "apple", "price": 120}))

{'ResponseMetadata': {'RequestId': 'KS5A9R2ONP5BVK1SK7EH98B89VVV4KQNSO5AEMVJF66Q9ASUAAJG', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'Server', 'date': 'Thu, 06 Aug 2020 17:42:30 GMT', 'content-type': 'application/x-amz-json-1.0', 'content-length': '2', 'connection': 'keep-alive', 'x-amzn-requestid': 'KS5A9R2ONP5BVK1SK7EH98B89VVV4KQNSO5AEMVJF66Q9ASUAAJG', 'x-amz-crc32': '2745614147'}, 'RetryAttempts': 0}}

items

Parameters

  • (required) key: str

    fruit
    
  • (required) value: dict | list | str | bytes | int | float | ...

    {"name": "apple", "price": 120}

Returns

  • DynamoDB put result : dict

🌱 Get

Use this function to get data from DynamoDB Table.

Examples

>>> print(handler.get(["fruit"]))
{'fruit': {'name': 'apple', 'price': 120}}

>>> print(handler.get("fruit"))
{'fruit': {'name': 'apple', 'price': 120}}

Parameters

  • (required) keys: list | str

    • list of key or key

Returns

  • Get result : dict

🌱 Get All

Use this function to get all data from DynamoDB Table.

Examples

>>> print(handler.get_all())
{'fruit': {'name': 'apple', 'price': 120}, 'fruit-2': {'name': 'banana', 'price': 121}}

Parameters

Returns

  • all data of the table : dict

🌱 Delete

Use this function to delete data from DynamoDB Table.

Examples

>>> print(handler.delete(["fruit"]))
...
>>> print(handler.delete("fruit"))
...

Parameters

  • (required) keys: list | str

    • list of key or key

Returns

  • dynamoDB delete result list : list

🎉 Acknowledgements

  • Title icon made by Freepik.

  • If you have a problem. please make issue.

  • Please help develop this project 😀

  • Thanks for reading 😄