{"id":21068359,"url":"https://github.com/druids/pydjamodb","last_synced_at":"2025-05-16T03:33:11.541Z","repository":{"id":44909277,"uuid":"314236878","full_name":"druids/pydjamodb","owner":"druids","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-19T09:19:32.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-16T01:50:20.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/druids.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-11-19T12:09:20.000Z","updated_at":"2023-02-04T07:11:43.000Z","dependencies_parsed_at":"2023-02-10T21:50:12.837Z","dependency_job_id":null,"html_url":"https://github.com/druids/pydjamodb","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fpydjamodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fpydjamodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fpydjamodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/druids%2Fpydjamodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/druids","download_url":"https://codeload.github.com/druids/pydjamodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225190392,"owners_count":17435414,"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","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":[],"created_at":"2024-11-19T18:20:04.355Z","updated_at":"2024-11-19T18:20:05.205Z","avatar_url":"https://github.com/druids.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Prolog\n======\n\n`pydjamodb` library is Django connector to the AWS DynamoDB. As a base is used `PynamoDB` library which models is transformed into `Django` model structure with the querysets and managers.\n\n[![Coverage Status](https://coveralls.io/repos/github/druids/pydjamodb/badge.svg?branch=master)](https://coveralls.io/github/druids/pydjamodb?branch=master)\n\nInstallation\n------------\n\n- Install `pydjamodb` with the `pip` command:\n\n```bash\npip install pydjamodb\n```\n\n- Set ``pydjamodb.test_runner.DynamoDBTestDiscoverRunner`` as your Django test runner:\n\n```python\nTEST_RUNNER = 'pydjamodb.test_runner.DynamoDBTestDiscoverRunner'\n```\n\n- Set configuration of your DynamoDB database:\n\n```python\nPYDJAMODB_DATABASE = {\n    'HOST': '',\n    'AWS_ACCESS_KEY_ID': '',\n    'AWS_SECRET_ACCESS_KEY': '',\n    'AWS_REGION': '',\n    'TABLE_PREFIX': 'some-prefix',\n    'BILLING_MODE': 'PAY_PER_REQUEST',\n    'TAGS': {\n        'tag_name': 'tag',\n    }\n}\n```\n\nUsage\n-----\n\nPyDjamoDB is common to Django models:\n\n```python\nfrom pynamodb.indexes import AllProjection, GlobalSecondaryIndex\n\nfrom pydjamodb.models import DynamoModel\nfrom pydjamodb.queryset import DynamoDBManager\nfrom pynamodb.attributes import (\n    MapAttribute, NumberAttribute, UnicodeAttribute, UTCDateTimeAttribute, BooleanAttribute, NumberAttribute\n)\n\n\nclass StringNumberIndex(GlobalSecondaryIndex):\n\n    string = UnicodeAttribute(hash_key=True)\n    number = NumberAttribute(range_key=True)\n\n    class Meta:\n        projection = AllProjection()\n\n\nclass TestDynamoModel(DynamoModel):\n\n    id = UnicodeAttribute(hash_key=True)\n    date = UTCDateTimeAttribute(range_key=True)\n    string = UnicodeAttribute(null=True)\n    number = NumberAttribute()\n    bool = BooleanAttribute()\n\n    string_number_index = StringNumberIndex()\n\n    objects_string_number = DynamoDBManager(index=string_number_index)\n\n    class Meta:\n        table_name = 'pydjamodbtest'\n```\n\nNow we can use model manager similar to Django model managers:\n\n```python\n# sets hash key for DynamoDB database and returns all elements with this key\nTestDynamoModel.objects.set_hash_key('test')\n# returns first instance with hash key 'test'\nTestDynamoModel.objects.set_hash_key('test').first()\n# returns first instance with hash key 'test'\nTestDynamoModel.objects.set_hash_key('test').last()\n# returns instance with hash key 'test' if there is only one instance, else raises MultipleObjectsReturned or ObjectDoesNotExist exception\nTestDynamoModel.objects.set_hash_key('test').get()\n# returns instance with hash key 'test' and range key equal to datetime.now() if there is only one instance, else raises MultipleObjectsReturned or ObjectDoesNotExist exception\nTestDynamoModel.objects.set_hash_key('test').get(date=datetime.now())\n# returns number of instances with hash key 'test'\nTestDynamoModel.objects.set_hash_key('test').count()\n# Filter elements by range key you can use operators (eq, startswith, gt, lt, gte, lte, between)\nTestDynamoModel.objects.set_hash_key('test').filter(date=datetime.now()) \n # sets paginator limitation to 10 items\nTestDynamoModel.objects.set_hash_key('test').set_limit(10)\n# returns key of the last item of the queryset result\nTestDynamoModel.objects.set_hash_key('test').set_limit(10).last_evaluated_key\n# sets index of pagination to specific key\nTestDynamoModel.objects.set_hash_key('test').set_limit(10).set_last_evaluated_key(key)\n# sets empty queryset\nTestDynamoModel.objects.set_hash_key('test').none()\n# reverses the order of returned items\nTestDynamoModel.objects.set_hash_key('test').set_scan_index_forward(False)\n# sets another pynamodb model index\nTestDynamoModel.objects.set_hash_key('test').set_index(TestDynamoModel.string_number_index)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdruids%2Fpydjamodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdruids%2Fpydjamodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdruids%2Fpydjamodb/lists"}