Skip to main content

A Python SDK for Sayari

Project description

Sayari-analytics Python Library

fern shield

The Sayari Python SDK provides convenient access to the Sayari API from applications written in Python.

Documentation

Please see our docs site for more info and or to get in touch with us.

Installation

Project Setup Guide

Before you begin using the Sayari API, it is essential to set up a Python virtual environment, install the required dependencies from requirements.txt, and configure the necessary environment variables using a .env file.

These steps ensure your environment is correctly isolated and properly configured for using the Sayari API.

1. Setup Python Virtual Environment

To keep your dependencies isolated, create and activate a Python virtual environment.

For macOS/Linux:

python3 -m venv venv
source venv/bin/activate

For Windows:

python -m venv venv
venv\Scripts\activate

This will create and activate a virtual environment in a folder named venv.

2. Install Dependencies from requirements.txt

Once your virtual environment is active, install the necessary dependencies from requirements.txt:

pip install -r requirements.txt

This will install all the required packages listed in the requirements.txt file.

3. Configure Environment Variables with .env

To securely store sensitive information like CLIENT_ID and CLIENT_SECRET, use a .env file.

Create a .env File

Create a file named .env in the root directory of your project and add the following content:

CLIENT_ID=your-client-id
CLIENT_SECRET=your-client-secret

Replace your-client-id and your-client-secret with the actual values provided by Sayari.

4. Deactivate the Virtual Environment

Once you're done with your development, you can deactivate the virtual environment:

deactivate

Usage

from sayari.client import Sayari

client = Sayari(
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET",
)

Async Client

from sayari.client import AsyncSayari

client = AsyncSayari(
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET",
)

Environment Variables

In your Python code, ensure you load the environment variables using python-dotenv:

from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Access the variables
client_id = os.getenv('CLIENT_ID')
client_secret = os.getenv('CLIENT_SECRET')

if client_id is None or client_secret is None:
    raise ValueError("CLIENT_ID and CLIENT_SECRET must be set in the .env file or as environment variables.")

Using env_loader.py

Once authenticated, you can use the client object to interact with the Sayari API. The client is returned by the load_env_vars_and_authenticate function, which handles all environment setup and authentication.

client = load_env_vars_and_authenticate()
# Now, you can use 'client' to make API calls.

Troubleshooting

  • Missing CLIENT_ID or CLIENT_SECRET: Ensure that your .env file contains both CLIENT_ID and CLIENT_SECRET. If not present, the script will exit with an error message.

  • Python Version Error: If the script exits with the message "Python 3.9.x or higher is required", make sure you are running the correct version of Python.

OAuth

The Sayari client includes automatic OAuth access token retrieval, refreshing it as needed. Simply specify the client_id and client_secret (shown above) and your access token will be used for every authenticated request.

Beta Status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version. This way, you can install the same version each time without breaking changes.

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

sayari-0.1.24.tar.gz (135.2 kB view details)

Uploaded Source

Built Distribution

sayari-0.1.24-py3-none-any.whl (272.9 kB view details)

Uploaded Python 3

File details

Details for the file sayari-0.1.24.tar.gz.

File metadata

  • Download URL: sayari-0.1.24.tar.gz
  • Upload date:
  • Size: 135.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.10 Linux/5.15.0-1074-azure

File hashes

Hashes for sayari-0.1.24.tar.gz
Algorithm Hash digest
SHA256 0e5c9e26f3c38db0fdd3f74b50243217d79a61eddd5646dade5ebf262bb51b20
MD5 9e03e0ec1900af09abc57812e55a8cc4
BLAKE2b-256 9c34653b4b4e440948845249e1bb7e48a45ab55eaaa9725674029cac2af1f670

See more details on using hashes here.

File details

Details for the file sayari-0.1.24-py3-none-any.whl.

File metadata

  • Download URL: sayari-0.1.24-py3-none-any.whl
  • Upload date:
  • Size: 272.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.10 Linux/5.15.0-1074-azure

File hashes

Hashes for sayari-0.1.24-py3-none-any.whl
Algorithm Hash digest
SHA256 0f85576b1f8e71b62b47d785ff49680959977c605599019a3519c2ce2719ead0
MD5 0e816b262ec4339d90f21188c848c13f
BLAKE2b-256 fb75db87c7b03d2afcdb5dd5d6b912e3397e323a7cd7ab728af2224e5176f24e

See more details on using hashes here.

Supported by

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