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.3.tar.gz (7.7 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.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamodb_not_orm-0.1.3.tar.gz
  • Upload date:
  • Size: 7.7 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.3.tar.gz
Algorithm Hash digest
SHA256 3d51e30c28f5e644b3ba9a0976cdd3f6766801d90bcd95aa0166f7e0257215c2
MD5 57298c8d2b92eb29018808f6b68df29d
BLAKE2b-256 6623710aa0168dd733c45056967b2996ed54af98e086fa8a088ee0e6c3439c29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamodb_not_orm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8a9b2d1238692a42545bb445faa1d20bff78a4fcd973165720f4c5edbd9b9d8b
MD5 86635e5c89289dc3937902a33144929d
BLAKE2b-256 a9300dc65d1169d2a66ce0e939ef214e83b144ebd9798a97221fbb39688e731c

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