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.1.tar.gz (7.4 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.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamodb_not_orm-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 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.1.tar.gz
Algorithm Hash digest
SHA256 c2101b6ff283638e7f35fe76f8ab161d083dd261521408910b38a29784585f53
MD5 a42060abb601c3d3fbbc9834ba5b0047
BLAKE2b-256 0784778e5eee5256f1f7f103dc8f5e298c12fbc96084af6553cb1c277a25eda8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamodb_not_orm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d75b74bc0439960c1d60051d16c2856d84448ca9eeb579ff4d1a15727fb069ab
MD5 b7b6ba2375d53b5ec2a6a23567dbd81b
BLAKE2b-256 d01aa46e3788707986972493a445753ed91ac72e88a76ea8d6ae3304ada0d33c

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