Skip to main content
Databases are managed services provided by Square Cloud that allow you to store and manage data for your applications. Supported databases include Redis, MongoDB, MySQL, and PostgreSQL.

Creating a database

client.create_database returns a Database object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    # Create a MongoDB database with 1024MB of memory
    database = await client.create_database(
        name='my_database',
        memory=1024,  # Memory in MB
        type='mongo',  # "redis", "mongo", "mysql", or "postgres"
        version='8.0.11'  # Optional - version will be inferred if not provided
    )
    
    print(database.id)               # Database identifier
    print(database.name)             # Database name
    print(database.type)             # Database type
    print(database.cluster)          # Database cluster
    print(database.memory)           # Memory allocated (MB)
    print(database.cpu)              # CPU allocated
    print(database.password)         # Database password
    print(database.connection_url)   # Connection URL
    print(database.certificate)      # TLS certificate

Retrieving database information

client.get_database_info returns a DatabaseInfo object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    database_info = await client.get_database_info(database_id='DATABASE_ID')
    
    print(database_info.id)            # Database identifier
    print(database_info.name)          # Database name
    print(database_info.type)          # Database type
    print(database_info.owner)         # Database owner user ID
    print(database_info.cluster)       # Database cluster
    print(database_info.ram)           # RAM usage in MB
    print(database_info.port)          # Database port
    print(database_info.created_at)    # Creation date (ISO 8601)
    print(database_info.created_at_datetime)  # Creation date as datetime object

Getting database status

client.get_database_status returns a StatusData object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    status = await client.get_database_status(database_id='DATABASE_ID')
    
    print(status.ram)      # RAM usage
    print(status.cpu)      # CPU usage percentage
    print(status.network)  # Network statistics
    print(status.running)  # Whether database is running
    print(status.storage)  # Storage usage

Listing all databases

client.all_databases_status returns a list of ResumedStatus objects.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    all_databases = await client.all_databases_status()
    
    for database in all_databases:
        print(f"Database: {database.id}")
        print(f"  CPU: {database.cpu}")
        print(f"  RAM: {database.ram}")
        print(f"  Running: {database.running}")

Starting a database

client.start_database returns a Response object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    response = await client.start_database(database_id='DATABASE_ID')
    print(f"Database started: {response.status}")

Stopping a database

client.stop_database returns a Response object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    response = await client.stop_database(database_id='DATABASE_ID')
    print(f"Database stopped: {response.status}")

Editing a database

client.edit_database returns a Response object. You can update the database name and/or memory allocation.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    # Update database name
    response = await client.edit_database(
        database_id='DATABASE_ID',
        name='new_database_name'
    )
    
    # Update memory allocation
    response = await client.edit_database(
        database_id='DATABASE_ID',
        memory=2048  # New memory in MB
    )
    
    # Update both name and memory
    response = await client.edit_database(
        database_id='DATABASE_ID',
        name='new_name',
        memory=2048
    )
    
    print(f"Database updated: {response.status}")

Deleting a database

client.delete_database returns a Response object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    response = await client.delete_database(database_id='DATABASE_ID')
    print(f"Database deleted: {response.status}")

Managing database credentials

Getting the database certificate

client.get_database_certificate returns a Certificate object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    certificate = await client.get_database_certificate(database_id='DATABASE_ID')
    
    # Save certificate to file
    certificate.save()  # Saves as 'certificate.pem' by default
    
    # Save certificate with custom filename
    certificate.save(filename='my_cert', export_to='cert')
    
    # Save certificate to specific directory
    certificate.save(dir='./certs', filename='my_cert', export_to='cert')

Resetting database password

client.reset_database_password returns a new password string.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    new_password = await client.reset_database_password(database_id='DATABASE_ID')
    print(f"New password: {new_password}")

Resetting database certificate

client.reset_database_certificate returns a Response object.
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    response = await client.reset_database_certificate(database_id='DATABASE_ID')
    print(f"Certificate reset: {response.status}")

Database data structures

Database

The Database object represents a newly created database with full details:
PropertyTypeDescription
idstrDatabase unique identifier
namestrDatabase name
typestrDatabase type (redis, mongo, mysql, postgres)
clusterstrDatabase cluster information
memoryintMemory allocated (MB)
cpuintCPU allocated (vCPU)
passwordstrDatabase password
certificateCertificateTLS certificate for secure connection
connection_urlstrConnection URL for the database

DatabaseInfo

The DatabaseInfo object contains information about an existing database:
PropertyTypeDescription
idstrDatabase unique identifier
namestrDatabase name
typestrDatabase type (redis, mongo, mysql, postgres)
clusterstrDatabase cluster information
ownerstrDatabase owner user ID
portintDatabase port
ramintCurrent RAM usage (MB)
created_atstrCreation timestamp (ISO 8601)

StatusData

The StatusData object contains real-time status information about a database:
PropertyTypeDescription
ramstrCurrent RAM usage
cpustrCurrent CPU usage percentage
networkdictNetwork statistics (upload/download)
runningboolWhether the database is running
storagestrStorage usage

Supported database types

Square Cloud supports the following databases:
TypeDefault VersionDescription
redis7.4.5In-memory data store for caching and real-time applications
mongo8.0.11NoSQL document database
mysql9.5Relational database
postgres17.6Advanced relational database