{"id":18485882,"url":"https://github.com/biomapas/b.dynamodbcommon","last_synced_at":"2025-09-13T03:43:35.099Z","repository":{"id":37770404,"uuid":"503780854","full_name":"Biomapas/B.DynamoDbCommon","owner":"Biomapas","description":"This python library makes it easier to develop your apps that use AWS DynamoDB (and especially that use PynamoDB ORM).","archived":false,"fork":false,"pushed_at":"2022-09-22T14:18:27.000Z","size":46,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-19T19:29:11.053Z","etag":null,"topics":["amazon-web-services","aws","dynamodb","pynamodb"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Biomapas.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-15T13:37:55.000Z","updated_at":"2023-05-30T20:45:53.000Z","dependencies_parsed_at":"2022-08-18T17:51:53.481Z","dependency_job_id":null,"html_url":"https://github.com/Biomapas/B.DynamoDbCommon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Biomapas/B.DynamoDbCommon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Biomapas%2FB.DynamoDbCommon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Biomapas%2FB.DynamoDbCommon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Biomapas%2FB.DynamoDbCommon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Biomapas%2FB.DynamoDbCommon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Biomapas","download_url":"https://codeload.github.com/Biomapas/B.DynamoDbCommon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Biomapas%2FB.DynamoDbCommon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274915585,"owners_count":25373193,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon-web-services","aws","dynamodb","pynamodb"],"created_at":"2024-11-06T12:47:02.887Z","updated_at":"2025-09-13T03:43:35.076Z","avatar_url":"https://github.com/Biomapas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# B.DynamoDbCommon\n\n![Pipeline](https://github.com/Biomapas/B.DynamoDbCommon/workflows/Pipeline/badge.svg?branch=master)\n\nA python library that makes it easier to interact with AWS DynamoDB tables.\n\n### Description\n\nThis library extends functionality of `pynamodb`, `boto3`, `json`, etc. modules\nto make it easier to interact with AWS DynamoDB tables. It contains various \nuseful functionalities:\n\n- Attributes (PynamoDB custom attributes);\n- Encoders (JSON encoders to work with pynamo/dynamo data types);\n- Models (PynamoDB custom models);\n- Seeds (Various data seeding functions);\n- Utils (Other cool functions);\n\n### Remarks\n\n[Biomapas](https://www.biomapas.com/) aims to modernise life-science industry by sharing its IT knowledge with other companies and the community. \nThis is an open source library intended to be used by anyone. \nImprovements and pull requests are welcome. \n\n### Related technology\n\n- Python3\n- Boto3\n- AWS DynamoDB\n- PynamoDB\n\n### Assumptions\n\nThis project assumes you know about DynamoDB service, and you prefer \nusing PynamoDB ORM to interact with DynamoDB tables.\n\n- Good Python skills and basis of OOP.\n- Good PynamoDB/DynamoDB skills.\n\n### Useful sources\n\n- DynamoDB API reference:\u003cbr\u003ehttps://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.API.html\n- DynamoDB boto3:\u003cbr\u003ehttps://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html\n- PynamoDB ORM documentation:\u003cbr\u003ehttps://pynamodb.readthedocs.io/en/latest/\n- PynamoDB ORM PyPi:\u003cbr\u003ehttps://pypi.org/project/pynamodb/\n\n### Install\n\nBefore installing this library, ensure you have these tools setup:\n\n- Python / Pip\n\nTo install this project from source run:\n\n```\npip install .\n```\n\nOr you can install it from a PyPi repository:\n\n```\npip install b-dynamodb-common\n```\n\n### Usage \u0026 Examples\n\nThis section shows various examples on how to use this library.\n\n#### Attributes\n\nAttributes module. Contains various custom PynamoDB ORM attribtues.\n\n- **Fernet attribute**\n\nCustom PynamoDB attribute that encrypts data in the database. \nUsing Fernet algorithm\n\n```python\nclass User(Model):\n    SECRET_ENCRYPTION_KEY = b'123456'\n\n    first_name = FernetAttribute(SECRET_ENCRYPTION_KEY)\n    last_name = FernetAttribute(SECRET_ENCRYPTION_KEY)\n```\n\n- **KMS attribute**\n\nCustom PynamoDB attribute that encrypts data in the database. \nUsing AWS KMS key to encrypt/decrypt data.\n\n```python\nboto_client = boto3.client('kms')\nkms_key_arn = 'arn:of:the:custom:kms:key'\n    \nclass User(Model):\n    first_name = KmsAttribute(boto_client, kms_key_arn)\n    last_name = KmsAttribute(boto_client, kms_key_arn)\n```\n\n#### Encoders\n\nEncoders module. Contains various encoding functionality.\n\n- **DynamoDbEncoder**\n\nCustom JSON encoder to handle DynamoDB data types.\n\n```python\ndata = {\n    'key1': 'RandomData',\n    'key2': OrderedSet([1, 2, 3]),\n    'key3': Decimal(1.1)\n}\n\njson.dumps(data, cls=DynamoDbEncoder)\n```\n\n- **PynamoDbEncoder**\n\nCustom JSON encoder to handle PynamoDB ORM and DynamoDB data types.\n\n```python\ndata = {\n    'key1': MapAttribute(map_key_1='RandomData'),\n    'key2': OrderedSet([1, 2, 3]),\n    'key3': Decimal(1.1)\n}\n\njson.dumps(data, cls=PynamoDbEncoder)\n```\n\n#### Models\n\nModels module. Contains various PynamoDB-based custom models.\n\n- **Permission model**\n\nModel that contains permissions attribute.\n\n```python\nentity = PermissionsModel()\nentity.pk = 'PK'\nentity.permissions = ['list', 'of', 'permissions']\nentity.save()\n\n# Add more permissions and save.\nentity.add_permission('permission')\nentity.save()\n```\n\n- **Model type factory**\n\nAllows to use the same pynamodb Model against multiple databases.\n\n```python\nfrom pynamodb.models import Model\n\n# Create your own model. Example, User model.\nclass User(Model): pass\n\n# Specify table 1 against which an example user will be saved.\nuser_model_table_1 = ModelTypeFactory(User).create('user_table_1', 'eu-west-1')\nuser_model_table_1(hash_key='hash', range_key='range').save()\n\n# Specify another table and save user in different table.\nuser_model_table_2 = ModelTypeFactory(User).create('user_table_2', 'eu-east-1')\nuser_model_table_2(hash_key='hash', range_key='range').save()\n```\n\n#### Seeds\n\nCurrently this module is empty.\n\n#### Utils\n\nUtilities module. Contains lots of cool functions.\n\n- **List function**\n\nWraps PynamoDB `query` and `scan` functions for better management.\n\n```python\nlist_function: PynamoDBListFunction[DummyEntity] = PynamoDBListFunction(DummyEntity.query, 'PK')\nitems = list(list_function())\n\n# You can also specify a transformer function to transform results before returning.\nlist_function: PynamoDBListFunction[DummyEntity] = PynamoDBListFunction(\n    # PynamoDB list function (query).\n    DummyEntity.query, \n    # Positional arguments.\n    'PK',\n    # Transformer function.\n    transformer=lambda item: item.pk\n)\n\n# Will contain only pks.\nids = list(list_function())\n```\n- **List results**\n\nWraps PynamoDB `query` and `scan` functions to handle recursive `last_evaluated_key` tokens.\n\n```python\nlist_function: PynamoDBListFunction[DummyEntity] = PynamoDBListFunction(\n    DummyEntity.scan,\n    limit=10,\n    filter_condition=DummyEntity.pk.is_in([...])\n)\n\nresult = PynamoDBListResult(list_function)\n\n# Fetch one time.\nresult.fetch(recursive=False)\n\n# Check whether all results have been fetched.\nresult.finished\n\n# If not, feel free to call it one more time and not worry about last_evaluated_key.\nresult.fetch(recursive=False)\n\n# If you want to retrieve absolutely all results in one call:\nresult.fetch(recursive=True) # Simple!\n```\n\n### Testing\n\nThis package has integration tests based on **pytest**.\nTo run tests simply run:\n\n```\npytest b_dynamodb_common_test/integration/tests\n```\n\n### Contribution\n\nFound a bug? Want to add or suggest a new feature? \nContributions of any kind are gladly welcome. \nYou may contact us directly, create a pull-request or an issue in github platform. \nLets modernize the world together.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiomapas%2Fb.dynamodbcommon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbiomapas%2Fb.dynamodbcommon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiomapas%2Fb.dynamodbcommon/lists"}