Table of Contents
This package contains a pure-Python CovenantSQL client library, based on PEP 249.
NOTE: PyCovenantSQL only support high level APIs defined in PEP 249.
- Python -- one of the following:
- HTTP Client:
- Requests >= 2.19
- CovenantSQL Proxy Server:
- CovenantSQL >= 0.0.2
Package is uploaded on PyPI.
You can install it with pip:
$ python3 -m pip install PyCovenantSQL
Documentation is available online: https://PyCovenantSQL.readthedocs.io/
Key file and database_id can get from: https://testnet.covenantsql.io/quickstart
For support, please refer to the StackOverflow.
The following examples make use of a simple table
CREATE TABLE `users` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL
);
import pycovenantsql.cursors
# user key file location
key = '/path/to/private.key'
# Connect to the database
connection = pycovenantsql.connect(host='localhost',
port=11108,
key=key,
database='database_id'
)
try:
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
# connection is autocommit. No need to commit in any case.
# connection.commit()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result)
finally:
connection.close()
This example will print:
{'password': 'very-secret', 'id': 1}
- DB-API 2.0: http://www.python.org/dev/peps/pep-0249
- CovenantSQL Website: https://covenantsql.io/
- CovenantSQL testnet quick start: https://testnet.covenantsql.io/quickstart
- CovenantSQL source code: https://github.com/CovenantSQL/CovenantSQL
PyCovenantSQL is released under the Apache 2.0 License. See LICENSE for more information.