Bloop: DynamoDB Modeling

DynamoDB's concurrency model is great, but using it correctly is tedious and unforgiving. Bloop manages that complexity for you.

Requires Python 3.6+

Features

  • Simple declarative modeling

  • Stream interface that makes sense

  • Easy transactions

  • Extensible type system, useful built-in types

  • Secure expression-based wire format

  • Expressive conditions

  • Model composition

  • Diff-based saves

  • Server-Side Encryption

  • Time-To-Live

  • Continuous Backups

  • On-Demand Billing

Ergonomics

The basics:

class Account(BaseModel):
    id = Column(UUID, hash_key=True)
    name = Column(String)
    email = Column(String)
    by_email = GlobalSecondaryIndex(
        projection='keys', hash_key='email')

engine.bind(Account)

some_account = Account(id=uuid.uuid4(), email='foo@bar.com')
engine.save(some_account)

q = engine.query(Account.by_email, key=Account.email == 'foo@bar.com')
same_account = q.one()

print(same_account.id)

Iterate over a stream:

template = "old: {old}\nnew: {new}\ndetails:{meta}"

stream = engine.stream(User, 'trim_horizon')
while True:
    record = next(stream)
    if not record:
        time.sleep(0.5)
        continue
    print(template.format(**record))

Use transactions:

with engine.transaction() as tx:
    tx.save(account)
    tx.delete(update_token, condition=Token.until <= now())

What's Next

Get started by installing Bloop, or check out a larger example.