<p align="center">
<a href="https://pypi.org/project/LucidDynamodb" target="_blank">
<img src="https://i.imgur.com/r9hHHUo.png" alt="LucidDynamodb">
</a>
</p>
<p align="center">
<em>A minimalistic wrapper to AWS DynamoDB</em>
</p>
<p align="center">
<a href="https://github.com/dineshsonachalam/Lucid-Dynamodb/actions" target="_blank">
<img src="https://github.com/dineshsonachalam/Lucid-Dynamodb/actions/workflows/pypi-deploy.yml/badge.svg" alt="Deployment">
</a>
<a href="https://pypi.org/project/LucidDynamodb" target="_blank">
<img src="https://img.shields.io/pypi/v/LucidDynamodb?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://github.com/dineshsonachalam/Lucid-Dynamodb/blob/master/LICENSE" target="_blank">
<img src="https://img.shields.io/apm/l/atomic-design-ui.svg" alt="MIT License">
</a>
</p>
## Installation
<div class="termy">
```console
pip install LucidDynamodb
```
</div>
**Note:** <a href="https://gist.github.com/dineshsonachalam/88f55b28c1f0c1ce93421f5a8f33e84a"> Prerequisite for Python3 development </a>
## Table of Contents
- [Example](#example)
- [Create a new table](#1-create-a-new-table)
- [Get all table names](#2-get-all-table-names)
- [Create a New Item](#3-create-a-new-item)
- [Read an Item](#4-read-an-item)
- [Increase an existing attribute value](#5-increase-an-existing-attribute-value)
- [Update existing attribute in an item](#6-update-existing-attribute-in-an-item)
- [Add a new attribute in an item](#7-add-a-new-attribute-in-an-item)
- [Add an attribute to the list](#8-add-an-attribute-to-the-list)
- [Add an attribute to the string set](#9-add-an-attribute-to-the-string-set)
- [Delete an attribute from the string set](#10-delete-an-attribute-from-the-string-set)
- [Delete an attribute from an item](#11-delete-an-attribute-from-an-item)
- [Read items by filter](#12-read-items-by-filter)
- [Delete a table](#13-delete-a-table)
## Example
### 1. Create a new table
```Python
from LucidDynamodb.Operations import DynamoDb
import os
import logging
import uuid
from boto3.dynamodb.conditions import Key
logging.basicConfig(level=logging.INFO)
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
table_schema = {
"TableName": "dev_jobs",
"KeySchema": [
{
"AttributeName": "company_name",
"KeyType": "HASH"
},
{
"AttributeName": "role_id",
"KeyType": "RANGE"
}
],
"AttributeDefinitions": [
{
"AttributeName": "company_name",
"AttributeType": "S"
},
{
"AttributeName": "role_id",
"AttributeType": "S"
}
],
"GlobalSecondaryIndexes": [],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
}
if __name__ == "__main__":
db = DynamoDb(region_name="us-east-1",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
table_creation_status = db.create_table(
TableName=table_schema.get("TableName"),
KeySchema=table_schema.get("KeySchema"),
AttributeDefinitions=table_schema.get("AttributeDefinitions"),
GlobalSecondaryIndexes=table_schema.get("GlobalSecondaryIndexes"),
ProvisionedThroughput=table_schema.get("ProvisionedThroughput")
)
if(table_creation_status == True):
logging.info("{} table created successfully".format(table_schema.get("TableName")))
else:
logging.error("{} table creation failed".format(table_schema.get("TableName")))
```
**Output:**
```
INFO:root:dev_jobs table created successfully
```
### 2. Get all table names
```Python
from LucidDynamodb.Operations import DynamoDb
import os
import logging
import uuid
from boto3.dynamodb.conditions import Key
logging.basicConfig(level=logging.INFO)
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
if __name__ == "__main__":
db = DynamoDb(region_name="us-east-1",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
table_names = db.read_all_table_names()
logging.info("Table names: {}".format(table_names))
```
**Output:**
```
INFO:root:Table names: ['dev_jobs', 'user']
```
### 3. Create a New Item
```Python
from LucidDynamodb.Operations import DynamoDb
import os
import logging
import uuid
from boto3.dynamodb.conditions import Key
logging.basicConfig(level=logging.INFO)
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
if __name__ == "__main__":
db = DynamoDb(region_name="us-east-1",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
item_creation_status = db.create_item(
TableName="dev_jobs",
Item={
"company_name": "Google",
"role_id": str(uuid.uuid4()),
"role": "Software Engineer 1",
"salary": "$1,50,531",
"locations": ["Mountain View, California", "Austin, Texas", "Chicago, IL"],
"yearly_hike_percent": 8,
"benefits": set(["Internet, Medical, Edu reimbursements",
"Health insurance",
"Travel reimbursements"
]),
"overall_review":{
"overall_rating" : "4/5",
"compensation_and_benefits": "3.9/5"
}
}
)
if(item_creation_status == True):
logging.info("Item created successfully")
else:
logging.warning("Item creation failed")
```
**Output:**
```
INFO:root:Item created successfully
```
### 4. Read an Item
```Python
from LucidDynamodb.Operations import DynamoDb
import os
import logging
import uuid
from boto3.dynamodb.conditions import Key
logging.basicConfig(level=logging.INFO)
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
if __name__ == "__main__":
db = DynamoDb(region_name="us-east-1",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
item = db.read_item(
TableName="dev_jobs",
Key={
"company_name": "Google",
"role_id": "e85f79a7-0857-4086-afbd-da13ec76b442"
})
if(item != None):
logging.info("Item: {}".format(item))
else:
logging.warning("Item doesn't exist")
```
**Output:**
```
INFO:root:Item:
{
'locations': ['Mountain View, California', 'Austin, Texas', 'Chicago, IL'],
'role_id': 'e85f79a7-0857-4086-afbd-da13ec76b442',
'overall_review': {
'compensation_and_benefits': '3.9/5',
'overall_rating': '4/5'
},
'company_name': 'Google',
'role': 'Software Engineer 1',
'yearly_hike_percent': Decimal('8'),
'salary': '$1,50,531',
'benefits': {
'Health insurance',
'Travel reimbursements',
'Internet, Medical, Edu reimbursements'
}
}
```
### 5. Increase an existing attribute value
```Python
from LucidDynamodb.Operations import DynamoDb
import os
import logging
import uuid
from boto3.dynamodb.conditions import Key
logging.basicConfig(level=logging.INFO)
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
if __name__ == "__main__":
db = DynamoDb(region_name="us-east-1",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
increase_attribute_status = db.increase_attribute_value(
TableName='dev_jobs',
Key={
"company_name": "Google",
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共12个文件
txt:4个
py:3个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:LucidDynamodb-1.0.97.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
LucidDynamodb-1.0.97.tar.gz (12个子文件)
LucidDynamodb-1.0.97
PKG-INFO 31KB
LucidDynamodb.egg-info
PKG-INFO 31KB
requires.txt 33B
not-zip-safe 1B
SOURCES.txt 292B
top_level.txt 14B
dependency_links.txt 1B
setup.cfg 38B
LucidDynamodb
__init__.py 183B
Operations.py 14KB
setup.py 1KB
README.md 23KB
共 12 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功