The Supavisor library is a Python client for interacting with the Supavisor API. It simplifies the process of managing tenants on a Supavisor server, including adding, deleting, retrieving, and terminating tenants.
- Add Tenant: Easily add new tenants with specified parameters.
- Delete Tenant: Remove tenants from the Supavisor server.
- Get Tenant: Retrieve information about existing tenants.
- Terminate Tenant: Terminate tenant sessions.
To install the Supavisor library, you can use pip:
pip install supavisor- Python 3.7 or higher
- An active Supavisor server instance
- Supavisor API key
First, import the necessary modules and initialize the Supavisor client:
from supavisor.client import Supavisor
from pydantic import SecretStr
supavisor = Supavisor(
supavisor_url="http://your-supavisor-url",
supavisor_api_key=SecretStr("your-api-key"),
)To add a tenant, you need to specify the tenant name and parameters:
from supavisor.types import AddTenantParams, TenantParams, TenantUser
tenant = "tenant1"
params = AddTenantParams(
tenant=TenantParams(
db_database=tenant,
db_host="your-db-host",
db_port=your-db-port,
enforce_ssl=False,
require_user=True,
users=[
TenantUser(db_user="user", db_password="password")
],
)
)
await supavisor.add_tenant(tenant, params)To delete a tenant, simply call the delete_tenant method with the tenant name:
tenant = "tenant1"
await supavisor.delete_tenant(tenant)To retrieve information about a tenant, use the get_tenant method:
tenant = "tenant1"
tenant_info = await supavisor.get_tenant(tenant)
print(tenant_info)To terminate a tenant session, call the terminate_tenant method with the tenant name:
tenant = "tenant1"
await supavisor.terminate_tenant(tenant)- Ease of Use: Simplifies interactions with the Supavisor API using Python.
- Asynchronous Support: Utilizes aiohttp for efficient asynchronous HTTP requests.
- JSON Serialization: Uses orjson for fast and efficient JSON serialization.
- Type Safety: Leverages Pydantic for data validation and type checking.
- Initializes the Supavisor client with the base URL and API key.
- Creates an asynchronous context manager for aiohttp sessions.
- Adds a new tenant with the specified parameters.
- Deletes the specified tenant.
- Retrieves information about the specified tenant.
- Terminates the session of the specified tenant.
Here is an example of how to use the Supavisor library to add, get, delete, and terminate a tenant:
from supavisor.client import Supavisor
from supavisor.types import AddTenantParams, TenantParams, TenantUser
from pydantic import SecretStr
supavisor = Supavisor(
supavisor_url="http://your-supavisor-url",
supavisor_api_key=SecretStr("your-api-key"),
)
tenant = "tenant1"
params = AddTenantParams(
tenant=TenantParams(
db_database=tenant,
db_host="your-db-host",
db_port=your-db-port,
enforce_ssl=False,
require_user=True,
users=[
TenantUser(db_user="user", db_password="password")
],
)
)
# Add Tenant
await supavisor.add_tenant(tenant, params)
# Get Tenant
tenant_info = await supavisor.get_tenant(tenant)
print(tenant_info)
# Delete Tenant
await supavisor.delete_tenant(tenant)
# Terminate Tenant
await supavisor.terminate_tenant(tenant)The Supavisor library provides a convenient and efficient way to manage tenants on a Supavisor server. With its asynchronous support and type-safe approach, it is an excellent choice for developers looking to integrate Supavisor functionality into their Python applications.