Skip to content

Commit 6a2f6f4

Browse files
0xneobyteclaude
andcommitted
chore: bump version to 0.1.7 and document env var support
- Add CHANGELOG entry for 0.1.7 (2026-03-05) - Bump version in pyproject.toml and client.py - Update basic_usage.py example to use BrainusAI() without manual env var handling - Add tests for BRAINUS_API_KEY auto-read behaviour Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 80de68a commit 6a2f6f4

5 files changed

Lines changed: 40 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.7] - 2026-03-05
9+
10+
### Added
11+
12+
- Automatic environment variable support: `api_key` is now optional and falls back to `BRAINUS_API_KEY` environment variable, enabling `BrainusAI()` without passing credentials explicitly
13+
814
## [0.1.6] - 2025-12-12
915

1016
### Fixed
@@ -56,6 +62,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5662
- Full type hints with Pydantic models
5763
- Async/await support
5864

65+
[0.1.7]: https://github.com/BrainUsLK/brainus-ai-python/compare/v0.1.6...v0.1.7
66+
[0.1.6]: https://github.com/BrainUsLK/brainus-ai-python/compare/v0.1.5...v0.1.6
67+
[0.1.5]: https://github.com/BrainUsLK/brainus-ai-python/compare/v0.1.4...v0.1.5
5968
[0.1.4]: https://github.com/BrainUsLK/brainus-ai-python/compare/v0.1.3...v0.1.4
6069
[0.1.3]: https://github.com/BrainUsLK/brainus-ai-python/compare/v0.1.2...v0.1.3
6170
[0.1.2]: https://github.com/BrainUsLK/brainus-ai-python/compare/v0.1.1...v0.1.2

examples/basic_usage.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
"""Basic usage example for the Brainus AI Python SDK."""
22

33
import asyncio
4-
import os
54
from brainus_ai import BrainusAI
65

76

87
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:
8+
# Initialize client — reads BRAINUS_API_KEY from environment automatically
9+
async with BrainusAI() as client:
1710
# Example 1: Query with no filters
1811
print("Example 1: Simple query")
1912
print("-" * 50)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "brainus-ai"
7-
version = "0.1.6"
7+
version = "0.1.7"
88
description = "Official Python SDK for Brainus AI - RAG-powered educational content API"
99
readme = "README.md"
1010
license = {text = "MIT"}

src/brainus_ai/client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
from __future__ import annotations
44

5+
import os
6+
57
import httpx
68
from typing import Any
79

10+
_SDK_VERSION = "0.1.7"
11+
812
from .exceptions import (
913
AuthenticationError,
1014
RateLimitError,
@@ -30,7 +34,7 @@ class BrainusAI:
3034

3135
def __init__(
3236
self,
33-
api_key: str,
37+
api_key: str | None = None,
3438
base_url: str = "https://api.brainus.lk",
3539
timeout: float = 30.0,
3640
max_retries: int = 3,
@@ -39,13 +43,18 @@ def __init__(
3943
Initialize the Brainus AI client.
4044
4145
Args:
42-
api_key: Your Brainus AI API key (brainus_...)
46+
api_key: Your Brainus AI API key (brainus_...). If not provided,
47+
reads from the BRAINUS_API_KEY environment variable.
4348
base_url: Base URL for the API (default: production gateway)
4449
timeout: Request timeout in seconds
4550
max_retries: Maximum number of retry attempts for failed requests
4651
"""
52+
if api_key is None:
53+
api_key = os.environ.get("BRAINUS_API_KEY")
4754
if not api_key or not api_key.startswith("brainus_"):
48-
raise AuthenticationError("Invalid API key format. Expected format: brainus_...")
55+
raise AuthenticationError(
56+
"Invalid API key. Pass api_key or set the BRAINUS_API_KEY environment variable."
57+
)
4958

5059
self.api_key = api_key
5160
self.base_url = base_url.rstrip("/")
@@ -57,7 +66,7 @@ def __init__(
5766
headers={
5867
"X-API-Key": self.api_key,
5968
"Content-Type": "application/json",
60-
"User-Agent": "brainus-ai-python/0.1.0",
69+
"User-Agent": f"brainus-ai-python/{_SDK_VERSION}",
6170
},
6271
timeout=httpx.Timeout(timeout),
6372
transport=httpx.AsyncHTTPTransport(retries=max_retries),

tests/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,18 @@ def test_default_max_retries(self):
5353
def test_custom_max_retries(self):
5454
client = BrainusAI(api_key="brainus_abc123", max_retries=5)
5555
assert client.max_retries == 5
56+
57+
def test_reads_api_key_from_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
58+
monkeypatch.setenv("BRAINUS_API_KEY", "brainus_from_env_123")
59+
client = BrainusAI()
60+
assert client.api_key == "brainus_from_env_123"
61+
62+
def test_explicit_key_takes_priority_over_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
63+
monkeypatch.setenv("BRAINUS_API_KEY", "brainus_from_env_123")
64+
client = BrainusAI(api_key="brainus_explicit_456")
65+
assert client.api_key == "brainus_explicit_456"
66+
67+
def test_raises_when_no_key_and_no_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
68+
monkeypatch.delenv("BRAINUS_API_KEY", raising=False)
69+
with pytest.raises(AuthenticationError):
70+
BrainusAI()

0 commit comments

Comments
 (0)