ameliepy documentation

Python database driver for AmelieDB.

Installation

Instructions to install the ameliepy driver.

pip install ameliepy

Usage

Basic usage examples for connecting to AmelieDB and executing queries.

import amelie

with amelie.connect(host="http://localhost:3485") as conn:
   with conn.cursor() as cursor:
      cursor.execute("SELECT 1")
      row = cursor.fetchone()
      print(row)
      # Will output: 1

Passing Arguments to Queries

You can pass arguments to your SQL queries using placeholders in the query string using format or pyformat styles.

Format Style

import amelie

with amelie.connect(host="http://localhost:3485") as conn:
   with conn.cursor() as cursor:
      cursor.execute("SELECT * FROM users WHERE id = %s", (1,))
      row = cursor.fetchone()
      print(row)  # Will output the user with id 1

Pyformat Style

import amelie

with amelie.connect(host="http://localhost:3485") as conn:
   with conn.cursor() as cursor:
      cursor.execute("SELECT * FROM users WHERE id = %(user_id)s", {'user_id': 1})
      row = cursor.fetchone()
      print(row)  # Will output the user with id 1

Danger

SQL Injection: Only use the methods above to pass arguments only in second parameter of .execute(query, params).

NEVER DO THIS:

cursor.execute("SELECT * FROM users WHERE id = %s" % 1)