Skip to main content

A lightweight DynamoDB ORM alternative

Project description

DynamoDB Not ORM

A lightweight DynamoDB ORM alternative that provides a simple way to work with DynamoDB without the complexity of a full ORM.

Features

  • Simple data model definition with dataclasses
  • Type-safe field access and updates
  • Migration system for schema changes
  • CLI tools for database operations

Installation

pip install dynamodb-not-orm

Quick Start

from dataclasses import dataclass, field
from dynamodb_not_orm import DataModel, F
from aiodynamo.models import ReturnValues


@dataclass
class UserProfile(DataModel):
    full_name: str | None = None


@dataclass
class UserDataModel(DataModel):
    __table__ = "users"
    __pk__ = "user_id"
    __sk__ = "email"

    user_id: str | None = None
    email: str | None = None
    name: str | None = None
    age: int | None = None
    profile: UserProfile | None = field(default_factory=UserProfile)


# Create a user
user = UserDataModel(user_id="123", email="user@example.com", name="John Doe", age=30)

# Get the key for DynamoDB operations
key = user.key  # {'user_id': '123', 'email': 'user@example.com'}

# Create a key for a specific user
key = UserDataModel.key("123", "user@example.com")  # {'user_id': '123', 'email': 'user@example.com'}

# create CRUD model
from dynamodb_not_orm import BaseCRUD


class UserCRUD(BaseCRUD[UserDataModel]):
    ...

user_crud = UserCRUD('eu-east-1', 'dev')
user = await user_crud.update(user.key, user.to_update_expression(), return_values=ReturnValues.all_new)
await user_crud.update(user.key, F(UserDataModel.profile.full_name).set("John Doe"))
await user_crud.update(
    user.key, F.and_(
        F(UserDataModel.age).set(18),
        F(UserDataModel.profile.full_name).set("Jane Doe"),
    )
)

CLI Usage

Initialize the migration system:

not-orm init --aws-region us-east-1 --environment dev --app-name myapp

Create a new migration:

not-orm create-empty "add user table"

Run migrations:

not-orm migrate --aws-region us-east-1 --environment dev --app-name myapp

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamodb_not_orm-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamodb_not_orm-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file dynamodb_not_orm-0.1.0.tar.gz.

File metadata

  • Download URL: dynamodb_not_orm-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for dynamodb_not_orm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c4d8a6cf2f6de135940a62368f80acc4bdf5852fb9f57cbf94f9559d888a10d
MD5 70a40fb9979442fb2ba22b00afb79a95
BLAKE2b-256 2eb04ae4215656b15019071b935e0943ade877b7cb903b5998c4648b40ea83df

See more details on using hashes here.

File details

Details for the file dynamodb_not_orm-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamodb_not_orm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8dd9295de953a8659b6e884f28e838741ab22d78c26946885271ae829bce33
MD5 74a7d826a835adacb2425538efc8108b
BLAKE2b-256 c27b734584edcb2681c32a1666f9610109c951f39b79513a0d36e050edededc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page