{"id":9712,"library":"dyntastic","title":"Dyntastic","description":"Dyntastic is a Python library that provides an intuitive Object-Document Mapper (ODM) for Amazon DynamoDB, built on top of Pydantic for data validation and `boto3` for AWS interaction. It simplifies schema definition, data serialization, and common DynamoDB operations. The current version is 0.18.0, with minor releases occurring approximately every 1-2 months.","status":"active","version":"0.18.0","language":"en","source_language":"en","source_url":"https://github.com/nayaverdier/dyntastic","tags":["dynamodb","pydantic","aws","orm","odm"],"install":[{"cmd":"pip install dyntastic","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core data validation and serialization. Pydantic v2+ requires dyntastic >= 0.13.1.","package":"pydantic","optional":false},{"reason":"AWS SDK for Python, used for interacting with DynamoDB.","package":"boto3","optional":false}],"imports":[{"note":"The primary model class is directly available from the top-level package.","wrong":"from dyntastic.models import DyntasticModel","symbol":"DyntasticModel","correct":"from dyntastic import DyntasticModel"}],"quickstart":{"code":"import os\nfrom dyntastic import DyntasticModel\n\n# Set environment variable for DynamoDB region (or explicitly define __table_region__)\n# For local development, you might set DYNTASTIC_HOST='http://localhost:8000'\nos.environ['DYNTASTIC_REGION'] = os.environ.get('DYNTASTIC_REGION', 'us-east-1')\n\nclass User(DyntasticModel):\n    __table_name__ = \"DyntasticExampleUsers\"\n    __table_hash_key__ = \"user_id\"\n\n    user_id: str\n    name: str\n    email: str\n    age: int = 0\n\n    class Config:\n        table_create_args = {\n            \"BillingMode\": \"PAY_PER_REQUEST\"\n        }\n\n# Create table if it doesn't exist (optional, auto-creates on first write by default)\n# User.create_table()\n\n# Create a new user\nuser_data = {\"user_id\": \"user123\", \"name\": \"Alice\", \"email\": \"alice@example.com\", \"age\": 30}\nalice = User(**user_data)\nalice.save() # This will create the table if it doesn't exist\n\nprint(f\"Saved user: {alice}\")\n\n# Retrieve a user by their hash key\nretrieved_user = User.get(\"user123\")\nprint(f\"Retrieved user: {retrieved_user}\")\n\n# Update user\nif retrieved_user:\n    retrieved_user.age = 31\n    retrieved_user.save()\n    print(f\"Updated user age: {retrieved_user.age}\")\n\n# Delete user\nif retrieved_user:\n    retrieved_user.delete()\n    print(f\"Deleted user: {retrieved_user.user_id}\")\n\n# Clean up (optional: delete table)\n# User.delete_table()","lang":"python","description":"This quickstart demonstrates how to define a DyntasticModel, save, retrieve, update, and delete items. It assumes DynamoDB is available at the configured region/host. The `__table_name__` and `__table_hash_key__` define the DynamoDB table structure. `table_create_args` in `Config` can be used to specify creation parameters like `BillingMode`."},"warnings":[{"fix":"Ensure `dyntastic>=0.13.1` is installed if your project uses `pydantic>=2.0`. Verify your Pydantic version with `pip show pydantic`.","message":"Dyntastic versions prior to 0.13.1 had limited or no compatibility with Pydantic V2. If you are using Pydantic V2 (released with Pydantic 2.0+), you must upgrade Dyntastic to version 0.13.1 or newer.","severity":"breaking","affected_versions":"<0.13.1"},{"fix":"Upgrade to `dyntastic>=0.11.0` if you rely on transactions not committing on error. Review existing transaction error handling in older versions.","message":"Prior to version 0.11.0, the `transaction()` context manager would attempt to commit batch operations even if an exception was raised during its `__exit__`. This behavior was changed in 0.11.0 to prevent commits when an exception occurs.","severity":"gotcha","affected_versions":"<0.11.0"},{"fix":"Upgrade to `dyntastic>=0.17.0` to ensure correct handling of aliased keys in all operations, including deletion.","message":"Dyntastic versions prior to 0.17.0 had issues correctly handling field aliases, specifically causing problems with deleting items from tables where the hash key was defined using an alias.","severity":"gotcha","affected_versions":"<0.17.0"},{"fix":"If using `dyntastic<0.14.0`, you must explicitly define `__table_region__` and `__table_host__` on your `DyntasticModel` classes, or configure `boto3` directly. For `dyntastic>=0.14.0`, setting the environment variables is an option.","message":"For Dyntastic models, the `__table_region__` and `__table_host__` attributes can be implicitly set via `DYNTASTIC_REGION` and `DYNTASTIC_HOST` environment variables, respectively. This feature was introduced in version 0.14.0.","severity":"gotcha","affected_versions":"<0.14.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change the import statement to `from dyntastic import DyntasticModel`.","cause":"The `DyntasticModel` class, which is the base for all Dyntastic models, is directly available from the top-level `dyntastic` package.","error":"ImportError: cannot import name 'DyntasticModel' from 'dyntastic.models'"},{"fix":"If using `pydantic>=2.0`, ensure `dyntastic>=0.13.1` is installed. If using an older `pydantic` version, ensure `dyntastic` matches its expected Pydantic major version.","cause":"This error or similar Pydantic validation issues often arise when there's a mismatch between your Pydantic version and the `dyntastic` version's Pydantic compatibility (e.g., using `dyntastic<0.13.1` with `pydantic>=2.0`).","error":"pydantic.v1.error_wrappers.ValidationError: field required (type=value_error.missing)"},{"fix":"Upgrade `dyntastic` to version `0.16.0` or higher to resolve this transaction-related validation bug.","cause":"This specific validation error related to empty `ExpressionAttributeValue` during a transaction operation was a bug in Dyntastic versions prior to 0.16.0.","error":"Validation Error: ExpressionAttributeValue specified with no actual value for key: ... (during transaction)"},{"fix":"Upgrade `dyntastic` to version `0.17.0` or higher to correctly handle aliased hash keys during delete operations.","cause":"This error can occur in `dyntastic` versions prior to 0.17.0 when attempting to delete an item from a table where the hash key was defined using a field alias.","error":"botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the DeleteItem operation: The provided key element does not match the schema"}]}