{"id":23117497,"url":"https://github.com/micmurawski/pynamodb-utils","last_synced_at":"2025-08-16T22:30:33.482Z","repository":{"id":53789062,"uuid":"334639626","full_name":"micmurawski/pynamodb-utils","owner":"micmurawski","description":"Pynamodb Utils is a collection of small helper functions, utilities and classes which make common patterns easier. It helped me make my job easier in the past.","archived":false,"fork":false,"pushed_at":"2024-06-20T14:07:58.000Z","size":55,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-11T08:39:24.017Z","etag":null,"topics":["aws","dynamodb","pynamodb","query-language","search","utils-library"],"latest_commit_sha":null,"homepage":"","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/micmurawski.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-31T11:32:59.000Z","updated_at":"2024-06-20T14:06:53.000Z","dependencies_parsed_at":"2024-06-21T06:04:00.245Z","dependency_job_id":"62b8707e-eedc-4944-8e85-cfce91fa1249","html_url":"https://github.com/micmurawski/pynamodb-utils","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"4a413c54bdd5dd75d1ed346a4f0fc2b9a91d8e0e"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmurawski%2Fpynamodb-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmurawski%2Fpynamodb-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmurawski%2Fpynamodb-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micmurawski%2Fpynamodb-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micmurawski","download_url":"https://codeload.github.com/micmurawski/pynamodb-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230062329,"owners_count":18166871,"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":["aws","dynamodb","pynamodb","query-language","search","utils-library"],"created_at":"2024-12-17T04:22:08.664Z","updated_at":"2025-08-16T22:30:33.473Z","avatar_url":"https://github.com/micmurawski.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nPynamodb Utils is a collection of small helper functions, utilities and classes which make common patterns easier. It helped me make my job easier in the past.\n\n[![Tests](https://github.com/micmurawski/pynamodb-utils/actions/workflows/release.yml/badge.svg)](https://github.com/micmurawski/pynamodb-utils/actions/workflows/release.yml) [![pypi](https://img.shields.io/pypi/v/pynamodb-utils.svg)](https://pypi.org/project/pynamodb-utils/)\n\n## Examples are:\n\n - Models with automatic ``updated_at``, ``created_at`` and ``deleted_at`` fields\n - Attributes for enums and dynamic mappings\n - Class with methods that allow to generate from JSON/dict query/scan conditions\n\n## To install:\nRun ``pip install pynamodb-utils`` or execute ``python setup.py install`` in the source directory\n\n## Example of Usage\n\nTo setup pynamodb models with authomaticly generated timestamps and useful functions allowing serialization of scan conditions from JSON input from API.\n\n```python\nfrom datetime import timezone, datetime\nfrom pynamodb.attributes import UnicodeAttribute\nfrom pynamodb_utils import DynamicMapAttribute, AsDictModel,\nJSONQueryModel, TimestampedModel\n\n\nclass CategoryEnum(enum.Enum):\n    finance = enum.auto()\n    politics = enum.auto()\n\nclass PostCategoryCreatedAtGSI(GlobalSecondaryIndex):\n    category = EnumAttribute(hash_key=True, enum=CategoryEnum)\n    created_at = UTCDateTimeAttribute(range_key=True)\n\n    class Meta:\n        index_name = \"example-index-name\"\n        projection = AllProjection\n\nclass Post(AsDictModel, JSONQueryModel, TimestampedModel):\n    name = UnicodeAttribute(hash_key=True)\n    sub_name = UnicodeAttribute(range_key=True)\n    category = EnumAttribute(enum=CategoryEnum, default=CategoryEnum.finance)\n    content = UnicodeAttribute()\n    tags = DynamicMapAttribute(default={})\n    category_created_at_gsi = PostCategoryCreatedAtGSI()\n\n    class Meta:\n        table_name = 'example-table-name'\n        TZINFO = timezone.utc\n\nPost.create_table(read_capacity_units=10, write_capacity_units=10)\n\npost = Post(\n    name='A weekly news.',\n    sub_name='Shocking revelations',\n    content='Last week took place...',\n    category=CategoryEnum.finance,\n    tags={\n        \"type\": \"news\",\n        \"topics\": [\"stock exchange\", \"NYSE\"]\n    }\n)\npost.save()\n\ncondition = Post.make_index_query(\n    query={\n        \"created_at__lte\": str(datetime.now()),\n        \"sub_name__exists\": None,\n        \"category__equals\": \"finance\",\n        \"OR\": {\"tags.type__equals\": \"news\", \"tags.topics__contains\": [\"NYSE\"]},\n    }\n) # class method executes query on the most optimal index\nprint(next(results).as_dict())\n```\nThat lines of code should result with following output\n\n```\n{\n        'name': 'A weekly news.',\n        'created_at': '2019-01-01 00:00:00+00:00',\n        'updated_at': '2019-01-01 00:00:00+00:00',\n        'deleted_at': None,\n        'content': 'Last week took place...',\n        'tags': {\n            'type': 'news',\n            'topics': ['stock exchange', 'NYSE']\n        }\n    }\n```\n\n## Links\n* https://github.com/pynamodb/PynamoDB\n* https://pypi.org/project/pynamodb-utils/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicmurawski%2Fpynamodb-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicmurawski%2Fpynamodb-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicmurawski%2Fpynamodb-utils/lists"}