Skip to content

Commit 78c3305

Browse files
committed
Add initial implementation of Brainus AI Python SDK with core features and examples
- Create .gitignore to exclude build outputs, environment variables, and IDE files - Add README.md with project description, features, installation instructions, and resources - Implement basic usage example in examples/basic_usage.py - Define project metadata in pyproject.toml including dependencies and classifiers - Establish main client functionality in src/brainus_ai/client.py - Create custom exceptions in src/brainus_ai/exceptions.py - Define data models in src/brainus_ai/models.py for API interactions - Add PEP 561 marker file for type information in src/brainus_ai/py.typed
0 parents  commit 78c3305

9 files changed

Lines changed: 637 additions & 0 deletions

File tree

.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Build outputs
2+
dist/
3+
build/
4+
*.egg-info/
5+
*.egg
6+
*.whl
7+
8+
# Environment variables
9+
.env
10+
.env.local
11+
.env.*.local
12+
13+
# Virtual environments
14+
venv/
15+
env/
16+
ENV/
17+
.venv/
18+
19+
# IDE
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# OS
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Python
31+
__pycache__/
32+
*.py[cod]
33+
*$py.class
34+
*.so
35+
.Python
36+
37+
# Testing
38+
.pytest_cache/
39+
.coverage
40+
htmlcov/
41+
.tox/
42+
43+
# Jupyter
44+
.ipynb_checkpoints/
45+
46+
# mypy
47+
.mypy_cache/
48+
.dmypy.json
49+
dmypy.json
50+
51+
# Temporary files
52+
*.tmp
53+
*.temp

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Brainus AI Python SDK
2+
3+
Official Python SDK for the Brainus AI API - RAG-powered educational content queries with citations.
4+
5+
[![PyPI version](https://badge.fury.io/py/brainus-ai.svg)](https://badge.fury.io/py/brainus-ai)
6+
[![Python Support](https://img.shields.io/pypi/pyversions/brainus-ai.svg)](https://pypi.org/project/brainus-ai/)
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8+
9+
## Features
10+
11+
- Async-first - Built with `httpx` for modern async/await patterns
12+
- Type-safe - Full type hints with Pydantic models
13+
- Automatic retries - Configurable retry logic for resilience
14+
- Error handling - Custom exceptions for different error cases
15+
- Citation support - Get source documents with page numbers
16+
- Usage tracking - Monitor your API usage and quotas
17+
18+
## Installation
19+
20+
```bash
21+
pip install brainus-ai
22+
```
23+
24+
## Documentation
25+
26+
Full documentation, quick start guide, API reference, and examples are available at:
27+
28+
**https://developers.brainus.lk/docs/sdks/python**
29+
30+
## Resources
31+
32+
- [Documentation](https://developers.brainus.lk/docs/sdks/python)
33+
- [Get API Key](https://developer.brainus.lk/dashboard/keys)
34+
- [Support](https://github.com/brainus/brainus-ai-python/issues)
35+
- [Website](https://brainus.lk)
36+
- [Developer Portal](https://developer.brainus.lk)
37+
38+
## License
39+
40+
MIT License - see [LICENSE](LICENSE) for details.
41+
42+
---
43+
44+
Made with ❤️ by the Brainus team

examples/basic_usage.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Basic usage example for the Brainus AI Python SDK."""
2+
3+
import asyncio
4+
import os
5+
from brainus_ai import BrainusAI
6+
7+
8+
async def main():
9+
# Get API key from environment variable
10+
api_key = os.getenv("BRAINUS_API_KEY")
11+
if not api_key:
12+
print("Error: BRAINUS_API_KEY environment variable not set")
13+
return
14+
15+
# Initialize the client
16+
async with BrainusAI(api_key=api_key) as client:
17+
# Example 1: Query with no filters
18+
print("Example 1: Simple query")
19+
print("-" * 50)
20+
response = await client.query(
21+
query="What is Object-Oriented Programming?",
22+
# store_id is optional - uses default if not provided
23+
)
24+
print(f"Answer: {response.answer}\n")
25+
26+
if response.has_citations:
27+
print("Citations:")
28+
for citation in response.citations:
29+
print(f" - {citation.document_name} (Pages: {citation.pages})")
30+
print()
31+
32+
# Example 2: Query with filters
33+
print("Example 2: Query with filters")
34+
print("-" * 50)
35+
from brainus_ai import QueryFilters
36+
37+
response = await client.query(
38+
query="Explain inheritance in programming",
39+
store_id="your_store_id", # Optional
40+
model="gemini-2.5-flash", # Optional
41+
filters=QueryFilters(subject="ICT", grade="12"),
42+
)
43+
print(f"Answer: {response.answer[:200]}...\n")
44+
45+
# Example 3: Get usage statistics
46+
print("Example 3: Usage statistics")
47+
print("-" * 50)
48+
stats = await client.get_usage()
49+
print(f"Total requests: {stats.total_requests}")
50+
print(f"Quota used: {stats.quota_percentage}%")
51+
if stats.quota_remaining:
52+
print(f"Quota remaining: {stats.quota_remaining}")
53+
print()
54+
55+
# Example 4: Get available plans
56+
print("Example 4: Available plans")
57+
print("-" * 50)
58+
plans = await client.get_plans()
59+
for plan in plans:
60+
print(f"{plan.name}:")
61+
print(f" Rate limit: {plan.rate_limit_per_minute} req/min")
62+
print(f" Monthly quota: {plan.monthly_quota or 'Unlimited'}")
63+
print(f" Price: LKR {plan.price_lkr or 0}/month")
64+
print(f" Allowed models: {', '.join(plan.allowed_models)}")
65+
print()
66+
67+
68+
if __name__ == "__main__":
69+
asyncio.run(main())
70+
71+
72+

pyproject.toml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "brainus-ai"
7+
version = "0.1.1"
8+
description = "Official Python SDK for Brainus AI - RAG-powered educational content API"
9+
readme = "README.md"
10+
license = {text = "MIT"}
11+
authors = [
12+
{name = "Brainus Team", email = "dev@brainus.lk"}
13+
]
14+
requires-python = ">=3.11"
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: MIT License",
19+
"Programming Language :: Python :: 3",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
"Typing :: Typed",
24+
"Operating System :: OS Independent",
25+
]
26+
keywords = ["brainus", "ai", "rag", "education", "api", "sdk"]
27+
28+
dependencies = [
29+
"httpx>=0.27.0",
30+
"pydantic>=2.9.0",
31+
"typing-extensions>=4.12.0; python_version<'3.13'",
32+
]
33+
34+
[project.optional-dependencies]
35+
dev = [
36+
"pytest>=8.3.0",
37+
"pytest-asyncio>=0.24.0",
38+
"pytest-httpx>=0.30.0",
39+
"mypy>=1.11.0",
40+
"ruff>=0.6.0",
41+
"build>=1.2.0",
42+
"twine>=5.1.0",
43+
]
44+
45+
[project.urls]
46+
Homepage = "https://developer.brainus.lk"
47+
Documentation = "https://developer.brainus.lk/docs"
48+
Repository = "https://github.com/brainus/brainus-ai-python"
49+
Issues = "https://github.com/brainus/brainus-ai-python/issues"
50+
Changelog = "https://github.com/brainus/brainus-ai-python/blob/main/CHANGELOG.md"
51+
52+
[tool.hatch.build.targets.wheel]
53+
packages = ["src/brainus_ai"]
54+
55+
[tool.ruff]
56+
line-length = 100
57+
target-version = "py311"
58+
59+
[tool.ruff.lint]
60+
select = ["E", "F", "I", "UP", "B", "SIM", "TCH"]
61+
ignore = []
62+
63+
[tool.mypy]
64+
python_version = "3.11"
65+
strict = true
66+
warn_return_any = true
67+
warn_unused_configs = true
68+
disallow_untyped_defs = true
69+
70+
71+

src/brainus_ai/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Brainus AI Python SDK
3+
4+
Official Python client for the Brainus AI API - RAG-powered educational content.
5+
"""
6+
7+
from .client import BrainusAI
8+
from .exceptions import (
9+
BrainusError,
10+
AuthenticationError,
11+
RateLimitError,
12+
QuotaExceededError,
13+
APIError,
14+
)
15+
from .models import QueryRequest, QueryResponse, Citation, UsageStats, Plan, QueryFilters, PlanInfo
16+
17+
__version__ = "0.1.0"
18+
19+
__all__ = [
20+
"BrainusAI",
21+
"BrainusError",
22+
"AuthenticationError",
23+
"RateLimitError",
24+
"QuotaExceededError",
25+
"APIError",
26+
"QueryRequest",
27+
"QueryResponse",
28+
"Citation",
29+
"UsageStats",
30+
"Plan",
31+
"QueryFilters",
32+
"PlanInfo",
33+
]
34+
35+
36+

0 commit comments

Comments
 (0)