Skip to main content

Supavisor Library README

Overview

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.

Features

  • 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.

Installation

To install the Supavisor library, you can use pip:

pip install supavisor

Getting Started

Prerequisites

  • Python 3.7 or higher
  • An active Supavisor server instance
  • Supavisor API key

Initialization

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"),
)

Add Tenant

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)

Delete Tenant

To delete a tenant, simply call the delete_tenant method with the tenant name:

tenant = "tenant1"
await supavisor.delete_tenant(tenant)

Get Tenant

To retrieve information about a tenant, use the get_tenant method:

tenant = "tenant1"
tenant_info = await supavisor.get_tenant(tenant)
print(tenant_info)

Terminate Tenant

To terminate a tenant session, call the terminate_tenant method with the tenant name:

tenant = "tenant1"
await supavisor.terminate_tenant(tenant)

Benefits

  • 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.

API Reference

Supavisor Class

__init__(supavisor_url: HttpUrl, supavisor_api_key: SecretStr)

  • Initializes the Supavisor client with the base URL and API key.

session()

  • Creates an asynchronous context manager for aiohttp sessions.

add_tenant(tenant: str, params: AddTenantParams) -> dict[str, Any]

  • Adds a new tenant with the specified parameters.

delete_tenant(tenant: str) -> bool

  • Deletes the specified tenant.

get_tenant(tenant: str) -> dict[str, Any]

  • Retrieves information about the specified tenant.

terminate_tenant(tenant: str) -> bool

  • Terminates the session of the specified tenant.

Example Usage

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)

Conclusion

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.

Release files for supavisor 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for supavisor 0.1.0
File Size Uploaded
supavisor-0.1.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supavisor 0.1.0
File Interpreter ABI Platform
supavisor-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / supavisor-0.1.0.tar.gz

Download URL supavisor-0.1.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d4bfe5f28e25cf09094e32a25eb45379a86f032e177109121c59a8ce66e36506
BLAKE2b-256 checksum
How to use checksums
334d4d092cecab1b49b898f1b88f3b4331ba36b8335172a0462664f6fddb4b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Darwin/23.1.0

Release files / supavisor-0.1.0-py3-none-any.whl

Download URL supavisor-0.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38ddd7518c62c56da5a988b70f1d4f886611a4ab0f7ebd827dd10fa81b934372
BLAKE2b-256 checksum
How to use checksums
f573b93d4c211f8772f62dd5b2a817d9723f3c6125ff3985912062b667354875
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page