Skip to main content

Shraga

Shraga is a modern AI application with a backend based on FastAPI and a frontend built with React, built by BigData Boutique and used by Pulse.

Installation and Setup

Requirements

  1. Python 3.11 or higher
  2. Pip
  3. Poetry (for dependency management)
  4. Node.js and pnpm (for frontend)

Backend Setup

First, install Poetry if you don't have it already:

pipx install poetry

Clone the repository and install dependencies:

git clone <repository-url>
cd shraga
poetry install --no-root
poetry run pre-commit install

To activate the virtual environment:

poetry shell
which python  # Verify the correct Python interpreter is being used

Running the Application

Backend

To run the backend server with hot-reloading enabled:

SHRAGA_FLOWS_PATH=flows CONFIG_PATH=config.demo.yaml uvicorn main:app --reload

Frontend

To run the frontend development server:

cd frontend
pnpm install  # Only needed first time or when dependencies change
pnpm run dev

By default, the frontend will be available at http://localhost:5000 and will connect to the backend API running on http://localhost:8000.

Configuration

Shraga uses YAML configuration files to manage its settings. The repository includes:

  • config.example.yaml: A template configuration file with documentation

You can specify which configuration file to use with the CONFIG_PATH environment variable.

Demo Flow

To run the demo flow without requiring an LLM, Elasticsearch, or Opensearch:

  1. Use the demo configuration file:

    export CONFIG_PATH=config.demo.yaml
    
  2. Run the backend with the demo flows:

    export SHRAGA_FLOWS_PATH=flows
    uvicorn main:app --reload
    

Development Tools

Several command-line tools are included with this package to help with development and management tasks:

User Management

# Create a user with basic authentication (interactive mode)
poetry run create-basic-auth-user

# Create a user with command-line arguments
poetry run create-basic-auth-user <email> <password> <config_file>

# Example
poetry run create-basic-auth-user user@example.com mypassword123 config.demo.yaml

This tool will:

  • Prompt you to enter a user email address (with validation)
  • Securely collect and validate a password
  • Ask for the configuration file to update
  • Generate a bcrypt hash of the password
  • Save the credentials to a text file for reference
  • Update the specified configuration file with the new user

Code Style

This project uses pre-commit hooks to enforce code style. They're installed with:

poetry run pre-commit install

API Documentation

Authentication

Shraga supports two authentication methods: Basic Authentication and JWT Authentication.

Basic Authentication

To authenticate with the API using basic authentication, you need to encode your credentials using base64.

Getting a Basic Auth Token

To get YOUR_TOKEN_HERE, encode your credentials using base64:

# Replace user@domain.com and your_password with actual credentials
echo -n "user@domain.com:your_password" | base64
# This outputs the token to use in the Authorization header

JWT Authentication

JWT (JSON Web Token) authentication allows for more secure and scalable authentication, especially useful when integrating Shraga with your own applications.

1. Configure JWT Secret in config.yaml

First, add a JWT secret to your configuration file:

auth:
  jwt:
    secret: "your-super-secret-jwt-key-here"  # Use a strong, randomly generated secret

Important: Use a strong, randomly generated secret in production. Never commit secrets to version control.

2. Getting a JWT Token

To obtain a JWT token, you'll need to implement a login endpoint in your application that verifies user credentials and returns a signed JWT. Here's an example using PyJWT:

import jwt
import time
from typing import Dict, Any

def create_jwt_token(user_email: str, user_id: int, user_name: str, secret: str) -> str:
    now = int(time.time())
    payload: Dict[str, Any] = {
        "sub": user_email,        # Subject (user identifier)
        "uid": user_id,           # User ID
        "name": user_name,        # User name
        "iat": now,               # Issued at
        "exp": now + 86400,       # Expires in 24 hours
    }
    return jwt.encode(payload, secret, algorithm="HS256")

Flow Run API

To generate a response programmatically, use the flow run endpoint. You can authenticate using either Basic or JWT authentication:

Using Basic Authentication

curl -X POST "http://myhost/api/flows/run" \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic YOUR_BASIC_TOKEN_HERE" \
  -d '{
    "flow_id": "flow name",
    "question": "this is my question?"
  }'

Using JWT Authentication

curl -X POST "http://myhost/api/flows/run" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN_HERE" \
  -d '{
    "flow_id": "flow name",
    "question": "this is my question?"
  }'

Report API

The Report API allows any user with analytics privileges to retrieve chat conversations from all organizations.

For generating chat reports, use the /api/report/export endpoint:

curl -X POST "http://localhost:5000/api/report/export" \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic YOUR_TOKEN_HERE" \
  -d '{
    "report_type": "history",
    "start": "2025-04-01 00:00:00",
    "end": "2025-06-01 00:00:00",
    "filters": { 
        "company_id": "1111",
        "email": "test@test.com"
    }
  }'

Parameters

  • report_type: "history" (required)
  • start: "YYYY-MM-DD HH:MM:SS" (optional)
  • end: "YYYY-MM-DD HH:MM:SS" (optional)
  • user_id: string (optional)
  • user_org: string (optional)

Prerequisites

The endpoint is available for users with analytics permission and history must be enabled in config.yaml.

Analytics permission can be configured in config.yaml:

Option 1: Domain-based access

history:
   enabled: true
   analytics: 
     domains:
       - domain.ltd

Option 2: User-based access

history:
   enabled: true
   analytics: 
      users:
         - username_from_auth.users

Project Structure

  • /shraga_common: Core library with reusable components
  • /scripts: Command-line utilities and helper scripts
  • /frontend: React-based web interface
  • /flows: Flow definitions for different use cases
  • /terraform: Infrastructure as code for deployment

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Metadata

Release files for shraga-common 0.9.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 shraga-common 0.9.0
File Size Uploaded
shraga_common-0.9.0.tar.gz 72.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shraga-common 0.9.0
File Interpreter ABI Platform
shraga_common-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 186.1 kB

Release files / shraga_common-0.9.0.tar.gz

Download URL shraga_common-0.9.0.tar.gz
Size 72.2 kB
Tags Source
SHA-256 checksum
How to use checksums
14d45e27e3baf5619024e4f668e38e9126ee66a1115f674c13704586221f5adc
BLAKE2b-256 checksum
How to use checksums
f872ab0cf496c0fb435d729dfc45134e0076a34376b7737ba893f81630eba88e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.

Transparency log

Release files / shraga_common-0.9.0-py3-none-any.whl

Download URL shraga_common-0.9.0-py3-none-any.whl
Size 113.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b1625af364fe6fab7242fbb84089d22aebc910d164776d91c44a5ddd3a776ca
BLAKE2b-256 checksum
How to use checksums
d07168d8df6493175e4931d595f25bca6faa6c0f80fa531738015bdc847898b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.3

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