reflectapi-runtime 0.17.2a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. reflectapi_runtime-0.17.2a1/.gitignore +5 -0
  2. reflectapi_runtime-0.17.2a1/PKG-INFO +85 -0
  3. reflectapi_runtime-0.17.2a1/README.md +50 -0
  4. reflectapi_runtime-0.17.2a1/pyproject.toml +133 -0
  5. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/__init__.py +109 -0
  6. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/auth.py +522 -0
  7. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/batch.py +168 -0
  8. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/client.py +1088 -0
  9. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/exceptions.py +129 -0
  10. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/hypothesis_strategies.py +288 -0
  11. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/middleware.py +258 -0
  12. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/option.py +296 -0
  13. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/response.py +135 -0
  14. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/sse.py +129 -0
  15. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/streaming.py +456 -0
  16. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/testing.py +398 -0
  17. reflectapi_runtime-0.17.2a1/src/reflectapi_runtime/types.py +34 -0
  18. reflectapi_runtime-0.17.2a1/tests/__init__.py +1 -0
  19. reflectapi_runtime-0.17.2a1/tests/test_auth.py +795 -0
  20. reflectapi_runtime-0.17.2a1/tests/test_auth_negative_cases.py +523 -0
  21. reflectapi_runtime-0.17.2a1/tests/test_batch.py +304 -0
  22. reflectapi_runtime-0.17.2a1/tests/test_client.py +430 -0
  23. reflectapi_runtime-0.17.2a1/tests/test_edge_cases.py +595 -0
  24. reflectapi_runtime-0.17.2a1/tests/test_enhanced_features.py +571 -0
  25. reflectapi_runtime-0.17.2a1/tests/test_exceptions.py +195 -0
  26. reflectapi_runtime-0.17.2a1/tests/test_middleware.py +704 -0
  27. reflectapi_runtime-0.17.2a1/tests/test_option.py +411 -0
  28. reflectapi_runtime-0.17.2a1/tests/test_pydantic_serialization.py +364 -0
  29. reflectapi_runtime-0.17.2a1/tests/test_response.py +165 -0
  30. reflectapi_runtime-0.17.2a1/tests/test_sse.py +282 -0
  31. reflectapi_runtime-0.17.2a1/tests/test_streaming.py +644 -0
  32. reflectapi_runtime-0.17.2a1/tests/test_testing.py +275 -0
@@ -0,0 +1,5 @@
1
+ /target
2
+ docs/book
3
+ .vscode/settings.json
4
+ *.pyc
5
+ __pycache__/
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: reflectapi-runtime
3
+ Version: 0.17.2a1
4
+ Summary: Runtime library for ReflectAPI Python clients
5
+ Project-URL: Homepage, https://github.com/thepartly/reflectapi
6
+ Project-URL: Repository, https://github.com/thepartly/reflectapi
7
+ Project-URL: Documentation, https://docs.rs/reflectapi/latest/reflectapi/
8
+ Author: Partly
9
+ License: MIT
10
+ Keywords: api,client,codegen,http,rest
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: httpx>=0.25.0
22
+ Requires-Dist: pydantic>=2.0.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: hypothesis>=6.0.0; extra == 'dev'
25
+ Requires-Dist: mypy>=1.5.0; extra == 'dev'
26
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
27
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
28
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
29
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
30
+ Provides-Extra: test
31
+ Requires-Dist: hypothesis>=6.0.0; extra == 'test'
32
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
33
+ Requires-Dist: pytest>=7.0.0; extra == 'test'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # reflectapi-runtime
37
+
38
+ Runtime support library for Python clients generated by
39
+ [`reflectapi`](https://github.com/thepartly/reflectapi). Generated code
40
+ imports from `reflectapi_runtime`; you don't normally call this library
41
+ directly.
42
+
43
+ ## What it provides
44
+
45
+ - `ClientBase` / `AsyncClientBase` — base classes used by the generated
46
+ `Client` / `AsyncClient`. They wrap `httpx` and handle request build-up,
47
+ Pydantic-based response validation, and middleware.
48
+ - `ApiResponse[T, E]` — typed wrapper around the response value, transport
49
+ metadata, and the optional typed error.
50
+ - `ApplicationError`, `NetworkError`, `TimeoutError`, `ValidationError` —
51
+ exceptions raised by the generated methods on non-2xx, transport, and
52
+ validation failures respectively.
53
+ - `ReflectapiOption` — three-state Option used by the generated models
54
+ (`some` / `none` / `undefined`) so absent and explicit-null can round-trip.
55
+ - Authentication helpers (`BearerTokenAuth`, `APIKeyAuth`, `BasicAuth`,
56
+ `OAuth2ClientCredentialsAuth`, `OAuth2AuthorizationCodeAuth`).
57
+ - Middleware, batching, and testing utilities (`MockClient`,
58
+ `CassetteMiddleware`).
59
+
60
+ ## Streaming endpoints
61
+
62
+ Endpoints declared with `Builder::stream_route` on the server are exposed on
63
+ the generated client as ordinary methods that return an iterator:
64
+
65
+ ```python
66
+ async with AsyncClient("http://localhost:3000") as client:
67
+ async for event in client.pets.cdc_events(headers=headers):
68
+ ... # process each event
69
+ ```
70
+
71
+ The sync client returns a regular `Iterator`; both validate each event
72
+ against the declared item model. The wire format is Server-Sent Events
73
+ (`data: <json>\n\n`); init failures (4xx/5xx) raise `ApplicationError` and
74
+ do not enter the iterator. Breaking out of the loop or calling
75
+ `stream.aclose()` releases the underlying HTTP connection.
76
+
77
+ Validation is strict: an event whose payload doesn't match the item model
78
+ (for example, an unknown discriminated-union variant added by a newer
79
+ server) raises `ValidationError` mid-stream and the iterator terminates.
80
+ Items received before the bad event are still delivered.
81
+
82
+ ## Compatibility
83
+
84
+ Python 3.12+. The package targets the same `reflectapi` minor version as
85
+ the schema you generate from; mismatches will surface at import time.
@@ -0,0 +1,50 @@
1
+ # reflectapi-runtime
2
+
3
+ Runtime support library for Python clients generated by
4
+ [`reflectapi`](https://github.com/thepartly/reflectapi). Generated code
5
+ imports from `reflectapi_runtime`; you don't normally call this library
6
+ directly.
7
+
8
+ ## What it provides
9
+
10
+ - `ClientBase` / `AsyncClientBase` — base classes used by the generated
11
+ `Client` / `AsyncClient`. They wrap `httpx` and handle request build-up,
12
+ Pydantic-based response validation, and middleware.
13
+ - `ApiResponse[T, E]` — typed wrapper around the response value, transport
14
+ metadata, and the optional typed error.
15
+ - `ApplicationError`, `NetworkError`, `TimeoutError`, `ValidationError` —
16
+ exceptions raised by the generated methods on non-2xx, transport, and
17
+ validation failures respectively.
18
+ - `ReflectapiOption` — three-state Option used by the generated models
19
+ (`some` / `none` / `undefined`) so absent and explicit-null can round-trip.
20
+ - Authentication helpers (`BearerTokenAuth`, `APIKeyAuth`, `BasicAuth`,
21
+ `OAuth2ClientCredentialsAuth`, `OAuth2AuthorizationCodeAuth`).
22
+ - Middleware, batching, and testing utilities (`MockClient`,
23
+ `CassetteMiddleware`).
24
+
25
+ ## Streaming endpoints
26
+
27
+ Endpoints declared with `Builder::stream_route` on the server are exposed on
28
+ the generated client as ordinary methods that return an iterator:
29
+
30
+ ```python
31
+ async with AsyncClient("http://localhost:3000") as client:
32
+ async for event in client.pets.cdc_events(headers=headers):
33
+ ... # process each event
34
+ ```
35
+
36
+ The sync client returns a regular `Iterator`; both validate each event
37
+ against the declared item model. The wire format is Server-Sent Events
38
+ (`data: <json>\n\n`); init failures (4xx/5xx) raise `ApplicationError` and
39
+ do not enter the iterator. Breaking out of the loop or calling
40
+ `stream.aclose()` releases the underlying HTTP connection.
41
+
42
+ Validation is strict: an event whose payload doesn't match the item model
43
+ (for example, an unknown discriminated-union variant added by a newer
44
+ server) raises `ValidationError` mid-stream and the iterator terminates.
45
+ Items received before the bad event are still delivered.
46
+
47
+ ## Compatibility
48
+
49
+ Python 3.12+. The package targets the same `reflectapi` minor version as
50
+ the schema you generate from; mismatches will surface at import time.
@@ -0,0 +1,133 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "reflectapi-runtime"
7
+ version = "0.17.2a1"
8
+ description = "Runtime library for ReflectAPI Python clients"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Partly"}
14
+ ]
15
+ keywords = ["api", "client", "codegen", "rest", "http"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Internet :: WWW/HTTP",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = [
28
+ "pydantic>=2.0.0",
29
+ "httpx>=0.25.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest>=7.0.0",
35
+ "pytest-asyncio>=0.21.0",
36
+ "pytest-cov>=4.0.0",
37
+ "hypothesis>=6.0.0",
38
+ "mypy>=1.5.0",
39
+ "ruff>=0.1.0",
40
+ ]
41
+ test = [
42
+ "pytest>=7.0.0",
43
+ "pytest-asyncio>=0.21.0",
44
+ "hypothesis>=6.0.0",
45
+ ]
46
+
47
+ [project.urls]
48
+ Homepage = "https://github.com/thepartly/reflectapi"
49
+ Repository = "https://github.com/thepartly/reflectapi"
50
+ Documentation = "https://docs.rs/reflectapi/latest/reflectapi/"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/reflectapi_runtime"]
54
+
55
+ [tool.hatch.build.targets.sdist]
56
+ include = [
57
+ "/src",
58
+ "/tests",
59
+ "/README.md",
60
+ ]
61
+
62
+ [tool.mypy]
63
+ python_version = "3.12"
64
+ strict = true
65
+ warn_return_any = true
66
+ warn_unused_configs = true
67
+ disallow_untyped_defs = true
68
+ disallow_incomplete_defs = true
69
+ check_untyped_defs = true
70
+ disallow_untyped_decorators = true
71
+ no_implicit_optional = true
72
+ warn_redundant_casts = true
73
+ warn_unused_ignores = true
74
+ warn_no_return = true
75
+
76
+ [tool.ruff]
77
+ target-version = "py312"
78
+ line-length = 88
79
+
80
+ [tool.ruff.lint]
81
+ select = [
82
+ "E", # pycodestyle errors
83
+ "W", # pycodestyle warnings
84
+ "F", # pyflakes
85
+ "I", # isort
86
+ "B", # flake8-bugbear
87
+ "C4", # flake8-comprehensions
88
+ "UP", # pyupgrade
89
+ "ARG", # flake8-unused-arguments
90
+ "SIM", # flake8-simplify
91
+ "TCH", # flake8-type-checking
92
+ ]
93
+ ignore = [
94
+ "B008", # do not perform function calls in argument defaults
95
+ "B024", # abstract base class without abstract methods
96
+ "B904", # raise from err/None - we handle this explicitly
97
+ "UP046", # Generic[T] vs type parameters - keeping for compatibility
98
+ "UP047", # Generic functions - keeping for compatibility
99
+ "SIM105", # contextlib.suppress - prefer explicit error handling
100
+ ]
101
+
102
+ [tool.ruff.lint.per-file-ignores]
103
+ "tests/**/*" = ["ARG", "S101", "F401", "F811"]
104
+
105
+ [tool.pytest.ini_options]
106
+ testpaths = ["tests"]
107
+ python_files = ["test_*.py"]
108
+ python_classes = ["Test*"]
109
+ python_functions = ["test_*"]
110
+ addopts = [
111
+ "--strict-markers",
112
+ "--strict-config",
113
+ "--cov=src/reflectapi_runtime",
114
+ "--cov-report=term-missing",
115
+ "--cov-report=html",
116
+ "--cov-report=xml",
117
+ ]
118
+ markers = [
119
+ "unit: Unit tests",
120
+ "integration: Integration tests",
121
+ "slow: Slow tests",
122
+ ]
123
+ asyncio_mode = "auto"
124
+
125
+ [dependency-groups]
126
+ dev = [
127
+ "mypy>=1.17.0",
128
+ "pytest>=8.4.1",
129
+ "pytest-asyncio>=1.1.0",
130
+ "pytest-cov>=6.2.1",
131
+ "ruff>=0.12.5",
132
+ "ty>=0.0.1a16",
133
+ ]
@@ -0,0 +1,109 @@
1
+ """ReflectAPI Python Runtime Library.
2
+
3
+ This package provides the core runtime components for ReflectAPI-generated clients.
4
+ """
5
+
6
+ from .auth import (
7
+ APIKeyAuth,
8
+ AuthHandler,
9
+ AuthToken,
10
+ BasicAuth,
11
+ BearerTokenAuth,
12
+ CustomAuth,
13
+ OAuth2AuthorizationCodeAuth,
14
+ OAuth2ClientCredentialsAuth,
15
+ api_key,
16
+ basic_auth,
17
+ bearer_token,
18
+ oauth2_authorization_code,
19
+ oauth2_client_credentials,
20
+ )
21
+ from .batch import BatchClient
22
+ from .client import AsyncClientBase, ClientBase
23
+ from .exceptions import (
24
+ ApiError,
25
+ ApplicationError,
26
+ NetworkError,
27
+ TimeoutError,
28
+ ValidationError,
29
+ )
30
+ from .hypothesis_strategies import (
31
+ HAS_HYPOTHESIS,
32
+ api_model_strategy,
33
+ enhanced_strategy_for_type,
34
+ strategy_for_pydantic_model,
35
+ strategy_for_type,
36
+ )
37
+ from .middleware import AsyncMiddleware
38
+ from .option import (
39
+ Option,
40
+ ReflectapiOption,
41
+ Undefined,
42
+ none,
43
+ serialize_option_dict,
44
+ some,
45
+ undefined,
46
+ )
47
+ from .response import ApiResponse, TransportMetadata
48
+ from .streaming import AsyncStreamingClient, StreamingResponse
49
+ from .testing import (
50
+ AsyncCassetteMiddleware,
51
+ CassetteClient,
52
+ CassetteMiddleware,
53
+ MockClient,
54
+ TestClientMixin,
55
+ )
56
+ from .types import BatchResult, ReflectapiEmpty, ReflectapiInfallible
57
+
58
+ __version__ = "0.17.2a1"
59
+
60
+ __all__ = [
61
+ # Authentication
62
+ "APIKeyAuth",
63
+ "AuthHandler",
64
+ "AuthToken",
65
+ "BasicAuth",
66
+ "BearerTokenAuth",
67
+ "CustomAuth",
68
+ "OAuth2AuthorizationCodeAuth",
69
+ "OAuth2ClientCredentialsAuth",
70
+ "api_key",
71
+ "basic_auth",
72
+ "bearer_token",
73
+ "oauth2_authorization_code",
74
+ "oauth2_client_credentials",
75
+ # Core
76
+ "ApiError",
77
+ "ApiResponse",
78
+ "ApplicationError",
79
+ "AsyncCassetteMiddleware",
80
+ "AsyncClientBase",
81
+ "AsyncStreamingClient",
82
+ "BatchClient",
83
+ "BatchResult",
84
+ "CassetteClient",
85
+ "CassetteMiddleware",
86
+ "ClientBase",
87
+ "HAS_HYPOTHESIS",
88
+ "AsyncMiddleware",
89
+ "MockClient",
90
+ "NetworkError",
91
+ "Option",
92
+ "ReflectapiEmpty",
93
+ "ReflectapiInfallible",
94
+ "ReflectapiOption",
95
+ "StreamingResponse",
96
+ "TestClientMixin",
97
+ "TimeoutError",
98
+ "TransportMetadata",
99
+ "Undefined",
100
+ "ValidationError",
101
+ "api_model_strategy",
102
+ "enhanced_strategy_for_type",
103
+ "none",
104
+ "serialize_option_dict",
105
+ "some",
106
+ "strategy_for_pydantic_model",
107
+ "strategy_for_type",
108
+ "undefined",
109
+ ]