Skip to main content

A SDK for integrating with Blesta

Project description

Blesta Python SDK

The Blesta Python SDK offers an intuitive API and CLI interface for seamless interaction with Blesta's REST API.

Requires Python >= 3.9.

๐Ÿš€ Quick and Easy Setup

  1. Create a Project Folder:

    mkdir my_project && cd my_project
    
  2. Install Blesta SDK:

    Using uv (recommended):

    uv init && uv add blesta_sdk
    

    Using pip:

    python3 -m venv venv
    source venv/bin/activate  # On Windows, use venv\Scripts\activate
    pip install blesta_sdk
    
  3. Configure API Credentials:

    Generate API credentials in Blesta's staff area and save them in a .env file in your project's root folder:

    BLESTA_API_URL=https://your-blesta-domain.com/api
    BLESTA_API_USER=your_api_user
    BLESTA_API_KEY=your_api_key
    

That's it. Let's roll!

๐Ÿ“– Usage Examples

Python API

from blesta_sdk.api import BlestaRequest

api = BlestaRequest("https://your-blesta-domain.com/api", "your_user", "your_key")

# GET request
response = api.get("clients", "getList", {"status": "active"})
if response.response_code == 200:
    print(response.response)  # parsed JSON "response" field
else:
    print(response.errors())

# POST request
response = api.post("clients", "create", {"firstname": "John", "lastname": "Doe"})

# PUT request
response = api.put("clients", "edit", {"client_id": 1, "firstname": "Jane"})

# DELETE request
response = api.delete("clients", "delete", {"client_id": 1})

# Inspect the last request made
print(api.get_last_request())  # {"url": "...", "args": {...}}

CLI

General Command Structure

blesta --model <model_name> --method <method_name> [--action GET] [--params key=value key2=value2] [--last-request]
  • --model: The API model to interact with (e.g., clients, services).
  • --method: The method to call on the specified model (e.g., getList, get, getCustomFields).
  • --action: The HTTP action to perform (default is GET).
  • --params: Optional parameters to pass to the method (e.g., key=value pairs).
  • --last-request: Displays the URL and parameters of the request that was just made.

The CLI reads BLESTA_API_URL, BLESTA_API_USER, and BLESTA_API_KEY from a .env file in the current directory.

Clients Model (API Documentation)

  • List all active clients:

    blesta --model clients --method getList --params status=active --last-request
    
  • Get details of a specific client:

    blesta --model clients --method get --params client_id=1 --last-request
    

Services Model (API Documentation)

  • List all active services:

    blesta --model services --method getList --params status=active --last-request
    
  • Count the active services for a client:

    blesta --model services --method getListCount --params client_id=1 status=active
    
  • List all services for a client:

    blesta --model services --method getAllByClient --params client_id=1 status=active --last-request
    

๐Ÿ“‚ Project Structure

Here's an overview of the project structure:

.
โ”œโ”€โ”€ .github
โ”‚   โ””โ”€โ”€ workflows
โ”‚       โ””โ”€โ”€ publish.yml
โ”œโ”€โ”€ CHANGELOG.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ examples
โ”‚   โ””โ”€โ”€ examples.sh
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ src
โ”‚   โ””โ”€โ”€ blesta_sdk
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ api
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ””โ”€โ”€ blesta_request.py
โ”‚       โ”œโ”€โ”€ cli
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ””โ”€โ”€ blesta_cli.py
โ”‚       โ””โ”€โ”€ core
โ”‚           โ”œโ”€โ”€ __init__.py
โ”‚           โ””โ”€โ”€ blesta_response.py
โ”œโ”€โ”€ tests
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ test_blesta_sdk.py
โ””โ”€โ”€ uv.lock
  • CHANGELOG.md: Version history and release notes.
  • LICENSE: The license file for the project.
  • README.md: The main documentation file for the project.
  • examples/: Contains example scripts and usage.
  • pyproject.toml: Configuration file for the project.
  • src/: The source code for the Blesta SDK.
    • blesta_sdk/: The main package for the SDK.
      • api/: API request handling (BlestaRequest).
      • cli/: Command-line interface implementation.
      • core/: Response handling (BlestaResponse).
  • tests/: Unit tests for the SDK.
  • uv.lock: Lock file for dependencies.

๐Ÿค Contribution

We welcome contributions! Whether it's a feature request, bug report, or pull request, we appreciate your input.

How to Contribute

  1. Fork the repository.
  2. Create a feature branch:
    git checkout -b feature/your-feature-name
    
  3. Commit your changes:
    git commit -m "Add your feature description here"
    
  4. Push to your branch:
    git push origin feature/your-feature-name
    
  5. Open a pull request:
    • Push your branch to GitHub.
    • Go to the repository on GitHub.
    • Click on the "Pull requests" tab.
    • Click "New pull request".
    • Select your branch and the main branch.
    • Add a descriptive title and detailed description.
    • Click "Create pull request".

This project is licensed under the MIT License

Happy coding! ๐ŸŽ‰

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blesta_sdk-0.1.7.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blesta_sdk-0.1.7-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file blesta_sdk-0.1.7.tar.gz.

File metadata

  • Download URL: blesta_sdk-0.1.7.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for blesta_sdk-0.1.7.tar.gz
Algorithm Hash digest
SHA256 8bc8ccee44722218841a32599e07fd682748f41e07e9c1335bed3b690aabebdd
MD5 21971a59d4913ba93b43d51a2f6d4f81
BLAKE2b-256 26c0ff7afb2be2081ab1efa8dfbc99b72abf93636e790bb2cccc6996958d64ba

See more details on using hashes here.

File details

Details for the file blesta_sdk-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: blesta_sdk-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for blesta_sdk-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c97ca5c36b7e7a015b3e9e20a00b75dd2e328f8de534f2d94d5939ad9b146c50
MD5 46345a09bafa7c3e858c60f3b56a6588
BLAKE2b-256 363d7e6bbdc154c56e2d02972a8ae0d96e9447b80fccc0bc0c03ae7ed4b027f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page