{"library":"pynamodb-attributes","title":"PynamoDB Attributes","description":"pynamodb-attributes provides common custom attribute types for PynamoDB models, extending the built-in attributes with specialized types like Timestamp, Timedelta, and Protobuf Enum attributes. It aims to simplify handling complex data types in DynamoDB. The current version is 0.5.1 and it generally follows the release cadence of its upstream dependency, PynamoDB.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pynamodb-attributes"],"cli":null},"imports":["from pynamodb_attributes import TimestampAttribute","from pynamodb_attributes import TimedeltaMsAttribute","from pynamodb_attributes import IntegerSetAttribute","from pynamodb_attributes import UnicodeProtobufEnumAttribute"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pynamodb.models import Model\nfrom pynamodb.attributes import UnicodeAttribute\nfrom pynamodb_attributes import TimestampAttribute, TimedeltaMsAttribute, IntegerSetAttribute\nimport datetime\n\n# Configure PynamoDB (for local DynamoDB for example)\n# from pynamodb.connection import Connection\n# Connection.tables = {}\n\nclass MyModel(Model):\n    class Meta:\n        table_name = 'my_test_model_table'\n        region = 'us-east-1'\n        # host = 'http://localhost:8000' # Uncomment for local DynamoDB\n        read_capacity_units = 1\n        write_capacity_units = 1\n\n    id = UnicodeAttribute(hash_key=True)\n    created_at = TimestampAttribute(null=True)\n    processing_time = TimedeltaMsAttribute(null=True)\n    favorite_numbers = IntegerSetAttribute(null=True)\n\n# Example Usage:\nif __name__ == '__main__':\n    # MyModel.create_table(wait=True) # Uncomment to create table\n    \n    item = MyModel(\n        id='item-123',\n        created_at=datetime.datetime.now(datetime.timezone.utc),\n        processing_time=datetime.timedelta(seconds=5, milliseconds=250),\n        favorite_numbers={1, 5, 10}\n    )\n    # item.save() # Uncomment to save item\n    \n    # retrieved_item = MyModel.get('item-123') # Uncomment to retrieve item\n    # print(f\"Retrieved: {retrieved_item.id}, Created: {retrieved_item.created_at}, \"\n    #       f\"Processed in: {retrieved_item.processing_time}, Favorites: {retrieved_item.favorite_numbers}\")\n","lang":"python","description":"This quickstart demonstrates how to define a PynamoDB model using custom attributes like `TimestampAttribute`, `TimedeltaMsAttribute`, and `IntegerSetAttribute`. It shows how to initialize an item with these types and how they would be stored and retrieved (commented out save/get operations requiring a running DynamoDB instance).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}