Skip to main content

A lightweight DynamoDB ORM alternative

Project description

DynamoDB Not ORM

PyPI version Python License: MIT Tests

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.2.tar.gz (7.3 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.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamodb_not_orm-0.1.2.tar.gz
  • Upload date:
  • Size: 7.3 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.2.tar.gz
Algorithm Hash digest
SHA256 99942a9b4e001ffbef40aac8cf9bc27c5fedd523e11afbfa8dea2d7294a445b6
MD5 299aa078d9f31247e2579aa65ba3ae34
BLAKE2b-256 5344c0c6f6811bc5c43fde14c2d581ea89bd99043f5c0f3b4f5c62238b98dcfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamodb_not_orm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0c14679b0f2efecbcc0adfe5e0817e6c7bc4fb9f2ff302a968683871db69fa67
MD5 8242a201b2cf3519298344b5fa964816
BLAKE2b-256 decd5846fa02f9199d9657b4bcd7320e7a8fc85258254e05c63880bae97346b3

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