Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
728533c
test: add failing tests for python sdk error hierarchy and base model
ejirocodes Mar 24, 2026
a8c18f3
feat: add python sdk package skeleton with error hierarchy
ejirocodes Mar 24, 2026
fbe1c5b
test: add failing tests for sync and async HTTP client
ejirocodes Mar 24, 2026
6b4cd35
test: add failing tests for jwt verification and jwks fetching
ejirocodes Mar 24, 2026
488e72a
feat: add user, team, session, contact channel, and permission pydant…
ejirocodes Mar 24, 2026
7b75ba8
feat: add jwt verification with async jwks fetcher and ttl cache
ejirocodes Mar 24, 2026
28171d4
feat: add sync and async HTTP client with retry logic
ejirocodes Mar 24, 2026
aecd4aa
feat: add project, api key, oauth, payment, and notification models
ejirocodes Mar 24, 2026
07c32d4
feat: add pagination support with cursor-based PaginatedResult
ejirocodes Mar 24, 2026
ea427ed
test: add failing tests for auth module
ejirocodes Mar 24, 2026
ad63cf0
test: add failing tests for token store subsystem
ejirocodes Mar 24, 2026
3ca5501
feat: add authenticate_request with jwt verification and partial decode
ejirocodes Mar 24, 2026
8060bc6
feat: export auth types and functions from stack_auth package
ejirocodes Mar 24, 2026
6b11389
feat: add token store with CAS-based refresh and dual locks
ejirocodes Mar 24, 2026
13f8875
test: add failing tests for StackServerApp and AsyncStackServerApp
ejirocodes Mar 25, 2026
fd3a816
feat: add StackServerApp and AsyncStackServerApp with user CRUD
ejirocodes Mar 25, 2026
7eb0c25
feat: export StackServerApp and AsyncStackServerApp from package root
ejirocodes Mar 25, 2026
e1ccb71
test: add failing tests for session management methods
ejirocodes Mar 25, 2026
7f4e3eb
feat: add session management methods to StackServerApp and AsyncStack…
ejirocodes Mar 25, 2026
3094338
test: add failing tests for team CRUD methods
ejirocodes Mar 25, 2026
3bf752f
feat: add team CRUD and API key lookup to StackServerApp
ejirocodes Mar 25, 2026
c48b9ca
test: add failing tests for team membership, invitations, and profiles
ejirocodes Mar 25, 2026
cd64ecb
feat: add team membership, invitations, and member profiles
ejirocodes Mar 25, 2026
6b012c0
test: add failing tests for permission management methods
ejirocodes Mar 25, 2026
e26f3a2
feat: add permission management methods to StackServerApp
ejirocodes Mar 25, 2026
c2f3a3a
test: add failing tests for contact channel verification methods
ejirocodes Mar 25, 2026
adeb156
feat: add contact channel verification methods to StackServerApp
ejirocodes Mar 25, 2026
7e41fc8
feat: add api key management methods to both facades
ejirocodes Mar 25, 2026
eae4842
feat: add oauth provider methods and connected accounts to both facades
ejirocodes Mar 25, 2026
e8ce41b
fix: update team member profile test to include required user_id field
ejirocodes Mar 25, 2026
0e6afdc
feat: add ServerItem, AsyncServerItem, and EmailDeliveryInfo models
ejirocodes Mar 25, 2026
c5ab839
feat: add payment methods and email sending to StackServerApp
ejirocodes Mar 25, 2026
299718c
feat: add data vault store with key-value operations
ejirocodes Mar 25, 2026
23c9f85
feat: add get_data_vault_store to facade classes and exports
ejirocodes Mar 25, 2026
f3780f2
docs: add comprehensive Google-style docstrings to all public SDK met…
ejirocodes Mar 25, 2026
c4ee7da
docs: add module docstring with quick-start example and complete PyPI…
ejirocodes Mar 25, 2026
1343d3a
test: add integration tests for payment, email, and data vault methods
ejirocodes Mar 25, 2026
0f39d10
fix: make metadata fields nullable on user and team models
ejirocodes Mar 25, 2026
c6da1ff
Merge branch 'stack-auth:dev' into feat/python-sdk
ejirocodes Mar 25, 2026
287183b
Merge branch 'feat/python-sdk' of https://github.com/ejirocodes/stack…
ejirocodes Mar 25, 2026
6138ff0
test: add failing tests for publishable_client_key and token store de…
ejirocodes Mar 25, 2026
0959548
fix: add publishable_client_key parameter and fix token store defaults
ejirocodes Mar 25, 2026
80f2c32
test: add failing tests for get_partial_user method
ejirocodes Mar 25, 2026
6c0c58d
feat: add get_partial_user method to StackServerApp and AsyncStackSer…
ejirocodes Mar 25, 2026
bfff27d
fix: make RequestLike runtime_checkable and remove type: ignore from …
ejirocodes Mar 25, 2026
7ec2e27
fix: add debug logging to authenticate_request exception handlers
ejirocodes Mar 25, 2026
b7e21a0
fix: replace broad exception catches with specific types and add debu…
ejirocodes Mar 25, 2026
625e3c0
test: add end-to-end integration test suite for live Stack Auth valid…
ejirocodes Mar 25, 2026
9ddc8aa
docs: add comprehensive README for python sdk
ejirocodes Mar 25, 2026
5c09ea7
Merge branch 'stack-auth:dev' into feat/python-sdk
ejirocodes Mar 26, 2026
d055007
fix: address PR review findings from bot analysis
ejirocodes Mar 26, 2026
5cbad57
fix: catch NotFoundError in data vault delete to match spec contract
ejirocodes Mar 26, 2026
37118e0
fix: skip aud/iss verification when not provided and narrow data vaul…
ejirocodes Mar 26, 2026
cac86ef
fix: add None guard before model_validate in get_item methods
ejirocodes Mar 26, 2026
131bb89
docs: clarify why 429 retries apply to all HTTP methods
ejirocodes Mar 26, 2026
e9105b3
fix: harden response parsing and add missing None guards
ejirocodes Mar 26, 2026
f7786c3
docs: add missing docstrings to reach 80% coverage threshold
ejirocodes Mar 26, 2026
b44fabc
fix: validate mutually exclusive product_id/product in grant_product
ejirocodes Mar 26, 2026
6aaa4b3
fix: guard against non-dict JSON in token refresh response
ejirocodes Mar 26, 2026
9aeed6b
fix: map TEAM_MEMBERSHIP_NOT_FOUND to NotFoundError
ejirocodes Mar 26, 2026
a6ac188
refactor: use modern Python 3.10+ imports in token store module
ejirocodes Mar 26, 2026
94293c1
fix: raise RateLimitError when 429 retries are exhausted
ejirocodes Mar 26, 2026
573fe23
fix: treat missing access_token in refresh response as failure
ejirocodes Mar 26, 2026
a26a682
refactor: extract _get_actual_status helper to deduplicate header par…
ejirocodes Mar 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: add failing tests for python sdk error hierarchy and base model
- Test StackAuthError base class storage and string representation
- Test all 13 category subclasses inherit from StackAuthError
- Test from_response() dispatch for known and unknown error codes
- Test StackAuthModel config and millis conversion
- Package skeleton with pyproject.toml (stubs only, tests expected to fail)
  • Loading branch information
ejirocodes committed Mar 24, 2026
commit 728533c87f1428f499c85a5ef868d2c8bc0ba0f5
27 changes: 27 additions & 0 deletions sdks/implementations/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Stack Auth Python SDK

Python SDK for [Stack Auth](https://stack-auth.com) - authentication, user management, and team management for your Python backend.

## Installation

```bash
pip install stack-auth
```

## Quick Start

```python
from stack_auth import StackServerApp

app = StackServerApp(
project_id="your-project-id",
secret_server_key="your-secret-key",
)

# Verify a request's access token
user = await app.authenticate_request(request)
```

## Requirements

- Python 3.10+
54 changes: 54 additions & 0 deletions sdks/implementations/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "stack-auth"
version = "0.1.0"
description = "Python SDK for Stack Auth"
readme = "README.md"
license = "MIT"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
]
dependencies = [
"httpx>=0.27,<1.0",
"pyjwt[crypto]>=2.9,<3.0",
"pydantic>=2.7,<3.0",
]

[project.optional-dependencies]
dev = [
"pytest>=8.0",
"pytest-asyncio>=1.0",
"respx>=0.22",
"ruff>=0.11",
"mypy>=1.10",
"pytest-cov>=5.0",
]

[tool.hatch.build.targets.wheel]
packages = ["src/stack_auth"]

[tool.ruff]
target-version = "py310"
line-length = 120

[tool.ruff.lint]
select = ["E", "F", "I", "N", "UP", "B", "SIM", "TCH"]

[tool.pytest.ini_options]
asyncio_mode = "auto"

[tool.mypy]
python_version = "3.10"
strict = true
1 change: 1 addition & 0 deletions sdks/implementations/python/src/stack_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Placeholder - will be populated after errors.py is implemented
3 changes: 3 additions & 0 deletions sdks/implementations/python/src/stack_auth/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DEFAULT_BASE_URL = "https://api.stack-auth.com"
SDK_NAME = "python"
API_VERSION = "v1"
8 changes: 8 additions & 0 deletions sdks/implementations/python/src/stack_auth/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

from typing import Mapping, Protocol


class RequestLike(Protocol):
@property
def headers(self) -> Mapping[str, str]: ...
1 change: 1 addition & 0 deletions sdks/implementations/python/src/stack_auth/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
1 change: 1 addition & 0 deletions sdks/implementations/python/src/stack_auth/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Placeholder - error hierarchy not yet implemented
Empty file.
1 change: 1 addition & 0 deletions sdks/implementations/python/src/stack_auth/models/_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Placeholder - base model not yet implemented
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions sdks/implementations/python/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture
def base_url() -> str:
return "https://api.stack-auth.com"
187 changes: 187 additions & 0 deletions sdks/implementations/python/tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
"""Tests for the Stack Auth error hierarchy and from_response() dispatch."""

from __future__ import annotations

from datetime import datetime, timezone

import pytest

from stack_auth.errors import (
AnalyticsError,
ApiKeyError,
AuthenticationError,
CliError,
ConflictError,
EmailError,
NotFoundError,
OAuthError,
PasskeyError,
PaymentError,
PermissionDeniedError,
RateLimitError,
StackAuthError,
ValidationError,
)
from stack_auth.models._base import StackAuthModel


class TestStackAuthErrorBasics:
"""Test StackAuthError base class storage and string representation."""

def test_stores_code_and_message(self) -> None:
err = StackAuthError("CODE", "msg")
assert err.code == "CODE"
assert err.message == "msg"

def test_str_contains_code_and_message(self) -> None:
err = StackAuthError("CODE", "msg")
s = str(err)
assert "CODE" in s
assert "msg" in s

def test_stores_details(self) -> None:
err = StackAuthError("CODE", "msg", {"key": "val"})
assert err.details == {"key": "val"}

def test_details_default_none(self) -> None:
err = StackAuthError("CODE", "msg")
assert err.details is None


class TestErrorSubclasses:
"""Test that all category subclasses exist and inherit from StackAuthError."""

@pytest.mark.parametrize(
"cls",
[
AuthenticationError,
NotFoundError,
ValidationError,
PermissionDeniedError,
ConflictError,
OAuthError,
PasskeyError,
ApiKeyError,
PaymentError,
EmailError,
RateLimitError,
CliError,
AnalyticsError,
],
)
def test_is_subclass_of_stack_auth_error(self, cls: type) -> None:
assert issubclass(cls, StackAuthError)

@pytest.mark.parametrize(
"cls",
[
AuthenticationError,
NotFoundError,
ValidationError,
PermissionDeniedError,
ConflictError,
OAuthError,
PasskeyError,
ApiKeyError,
PaymentError,
EmailError,
RateLimitError,
CliError,
AnalyticsError,
],
)
def test_can_be_caught_with_except_stack_auth_error(self, cls: type) -> None:
with pytest.raises(StackAuthError):
raise cls("TEST_CODE", "test message")


class TestFromResponse:
"""Test from_response() factory dispatch for known and unknown codes."""

def test_invalid_access_token_returns_authentication_error(self) -> None:
err = StackAuthError.from_response("INVALID_ACCESS_TOKEN", "bad token")
assert isinstance(err, AuthenticationError)
assert err.code == "INVALID_ACCESS_TOKEN"
assert err.message == "bad token"

def test_user_not_found_returns_not_found_error(self) -> None:
err = StackAuthError.from_response("USER_NOT_FOUND", "no user")
assert isinstance(err, NotFoundError)

def test_schema_error_returns_validation_error(self) -> None:
err = StackAuthError.from_response("SCHEMA_ERROR", "bad schema")
assert isinstance(err, ValidationError)

def test_team_permission_required_returns_permission_error(self) -> None:
err = StackAuthError.from_response("TEAM_PERMISSION_REQUIRED", "denied")
assert isinstance(err, PermissionDeniedError)

def test_team_already_exists_returns_conflict_error(self) -> None:
err = StackAuthError.from_response("TEAM_ALREADY_EXISTS", "conflict")
assert isinstance(err, ConflictError)

def test_oauth_connection_not_connected_returns_oauth_error(self) -> None:
err = StackAuthError.from_response("OAUTH_CONNECTION_NOT_CONNECTED_TO_USER", "no conn")
assert isinstance(err, OAuthError)

def test_passkey_authentication_failed_returns_passkey_error(self) -> None:
err = StackAuthError.from_response("PASSKEY_AUTHENTICATION_FAILED", "failed")
assert isinstance(err, PasskeyError)

def test_api_key_not_valid_returns_api_key_error(self) -> None:
err = StackAuthError.from_response("API_KEY_NOT_VALID", "invalid")
assert isinstance(err, ApiKeyError)

def test_product_already_granted_returns_payment_error(self) -> None:
err = StackAuthError.from_response("PRODUCT_ALREADY_GRANTED", "granted")
assert isinstance(err, PaymentError)

def test_email_rendering_error_returns_email_error(self) -> None:
err = StackAuthError.from_response("EMAIL_RENDERING_ERROR", "render fail")
assert isinstance(err, EmailError)

def test_unknown_code_returns_base_stack_auth_error(self) -> None:
err = StackAuthError.from_response("TOTALLY_UNKNOWN_CODE", "surprise")
assert type(err) is StackAuthError
assert err.code == "TOTALLY_UNKNOWN_CODE"
assert err.message == "surprise"

def test_from_response_preserves_details(self) -> None:
err = StackAuthError.from_response("USER_NOT_FOUND", "no user", {"user_id": "abc"})
assert err.details == {"user_id": "abc"}

def test_cli_auth_error_returns_cli_error(self) -> None:
err = StackAuthError.from_response("CLI_AUTH_ERROR", "cli fail")
assert isinstance(err, CliError)

def test_analytics_query_timeout_returns_analytics_error(self) -> None:
err = StackAuthError.from_response("ANALYTICS_QUERY_TIMEOUT", "timeout")
assert isinstance(err, AnalyticsError)


class TestErrorCodeMapCoverage:
"""Test that the error code map has comprehensive coverage."""

def test_error_code_map_has_at_least_90_entries(self) -> None:
from stack_auth.errors import _ERROR_CODE_MAP

assert len(_ERROR_CODE_MAP) >= 90, f"Expected >= 90 entries, got {len(_ERROR_CODE_MAP)}"


class TestStackAuthModel:
"""Test the StackAuthModel base class."""

def test_model_config_populate_by_name(self) -> None:
assert StackAuthModel.model_config.get("populate_by_name") is True

def test_model_config_extra_ignore(self) -> None:
assert StackAuthModel.model_config.get("extra") == "ignore"

def test_millis_to_datetime_converts_correctly(self) -> None:
result = StackAuthModel._millis_to_datetime(1711296000000)
expected = datetime(2024, 3, 24, 16, 0, tzinfo=timezone.utc)
assert result == expected

def test_millis_to_datetime_none_returns_none(self) -> None:
result = StackAuthModel._millis_to_datetime(None)
assert result is None