ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs ScyllaDB Cloud Getting Started Documentation ScyllaDB Alternator: Python Example

ScyllaDB Alternator: Python Example¶

Using the “Python AWS SDK” we can easily connect our project on any ScyllaDB instance (Local/Cloud) that is configured with Alternator flag.

Quick Start¶

Create a new folder

If you’re starting a new project, make sure to require the SDK package in your application.

sudo pip install --upgrade boto3

You can instantiate a new DynamoDB Client by using:

import boto3

alternator = boto3.resource('dynamodb',endpoint_url='http://localhost:8000',
                region_name='None', aws_access_key_id='None', aws_secret_access_key='None')

Queries¶

Here’s the DynamoDB queries used on this project so far:

Creating a Table¶

import boto3

alternator = boto3.resource('dynamodb',endpoint_url='http://localhost:8000',
                region_name='None', aws_access_key_id='None', aws_secret_access_key='None')

table = alternator.create_table(
    TableName="songs",
    KeySchema=[
        {'AttributeName': 'id', 'KeyType': 'HASH'},
        {'AttributeName': 'created_at', 'KeyType': 'RANGE'},
    ],
    AttributeDefinitions=[
        {'AttributeName': 'id', 'AttributeType': 'S'},
        {'AttributeName': 'created_at', 'AttributeType': 'S'},
        {'AttributeName': 'title', 'AttributeType': 'S'},
        {'AttributeName': 'artist', 'AttributeType': 'S'},
        {'AttributeName': 'album', 'AttributeType': 'S'},
    ],
    ProvisionedThroughput={'ReadCapacityUnits': 10, 'WriteCapacityUnits': 10}
);
table.wait_until_exists()

table.put_item(Item={
    'id': str(uuid.uuid4()),    
    'created_at': str(datetime.now()),
    'title': 'Song 1',
    'album': 'Album 1',
    'artist': 'artistName',
})

Adding Items¶

alternator = boto3.resource('dynamodb',endpoint_url='http://localhost:8000',
                region_name='None', aws_access_key_id='None', aws_secret_access_key='None')

table = alternator.Table('songs')

table.put_item(Item={
    'id': str(uuid.uuid4()),    
    'created_at': str(datetime.now()),
    'title': 'Song 1',
    'album': 'Album 1',
    'artist': 'artistName',
})

Listing Items¶


alternator = boto3.resource('dynamodb',endpoint_url='http://localhost:8000',
                region_name='None', aws_access_key_id='None', aws_secret_access_key='None')

table = alternator.Table('songs')

listSongs = table.scan()
enumSongList = list(enumerate(listSongs['Items']))

for rowIndex, song in enumSongList:
    print(f"Index: {rowIndex} | Title: {song['title']} | Album: {song['album']} ")

Delete Item¶


alternator = boto3.resource('dynamodb',endpoint_url='http://localhost:8000',
                region_name='None', aws_access_key_id='None', aws_secret_access_key='None')

table = alternator.Table('songs')
listSongs = table.scan()

table.delete_item(Key={
    'id': 'id',
    'created_at': 'y-m-d H:i:s'
})

Was this page helpful?

PREVIOUS
ScyllaDB Alternator: PHP Example
  • Create an issue
  • Edit this page

On this page

  • ScyllaDB Alternator: Python Example
    • Quick Start
    • Queries
      • Creating a Table
      • Adding Items
      • Listing Items
      • Delete Item
ScyllaDB Cloud Getting Started Documentation
  • Getting Started
  • Design and Data Model
  • Build with JavaScript
  • Build with Java
  • Build with Elixir
  • Build with Python
  • Build with Ruby
  • Build with Rust
  • Build with Csharp
  • Build with Golang
  • Getting Started GitHub Repository
  • Alternator: Getting Started
  • Alternator: Build with PHP
  • Alternator: Build with Python
  • Getting Started GitHub Repository
Docs Tutorials University Contact Us About Us
© 2025, ScyllaDB. All rights reserved. | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 05 May 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.6