Jump to content

Recommended Posts

Posted

Much of our company's product development begins as a Python project. Each project has its own request logic and environment variables. By installing blesta_sdk as a project dependency via pip, I can reuse the portable stuff without having to write custom connections and queries for each project.

Features

  • The original PHP SDK reimagined using Python's python-dotenv and Requests libraries.
  • Easy setup: Just add a local `.env` file to your project root, install `blesta_sdk` via pip, and you're ready to roll!

Installation

Step 1 -  Install the Package

Install the package via pip:
 

pip install blesta-sdk

### Configure the Environment

Step 2 - Add a `.env` file to your project root with the following variables:

BLESTA_API_URL=https://your-blesta-api-url.com
BLESTA_API_USER=your-api-user
BLESTA_API_KEY=your-api-key

That's it, your ready to make ANY Blesta Model API requests using the CLI or API method illustrated below.

Using Blesta SDK

Blesta CLI Client

The CLI client provides an easy way to interact with Blesta's REST API. For example, this command requests all the active clients:

blesta-cli --model clients --method getList --params status=active --last-request

Blesta API Client

You can pass Blesta API methods directly through the API client. Here's an example
 

import json
import os
from blesta_sdk import api
from dotenv import load_dotenv

load_dotenv()

# Create an instance of BlestaApi with the required arguments
blesta_api_url = os.getenv('BLESTA_API_URL')
blesta_api_user = os.getenv('BLESTA_API_USER')
blesta_api_key = os.getenv('BLESTA_API_KEY')

if not all([blesta_api_url, blesta_api_user, blesta_api_key]):
    raise ValueError("Missing one or more Blesta API environment variables")

blesta_api = api.BlestaApi(blesta_api_url, blesta_api_user, blesta_api_key)

# Submit the request
try:
    response = blesta_api.submit(method='getAll', model='clients')
    print(response.raw)
except Exception as e:
    print(f"An error occurred: {e}")

Links

- **PyPI**: https://pypi.org/project/blesta_sdk/
- **GitHub**: https://github.com/jwogrady/blesta_sdk

The code is published under MIT.  Please submit issues, features, etc. on the GitHub repo.

  • jwogrady changed the title to New Python Blesta SDK on PyPi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...