Skip to content

Commit 51c4025

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): OpenAPI spec update via Stainless API (#18)
1 parent 76e0208 commit 51c4025

94 files changed

Lines changed: 1743 additions & 1112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
echo "$HOME/.rye/shims" >> $GITHUB_PATH
2323
env:
2424
RYE_VERSION: 0.24.0
25-
RYE_INSTALL_OPTION: "--yes"
25+
RYE_INSTALL_OPTION: '--yes'
2626

2727
- name: Install dependencies
2828
run: |
@@ -39,3 +39,5 @@ jobs:
3939
- name: Ensure importable
4040
run: |
4141
rye run python -c 'import maisa'
42+
43+

‎.stats.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 15
1+
configured_endpoints: 14

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Most tests require you to [set up a mock server](https://github.com/stoplightio/
8686

8787
```bash
8888
# you will need npm installed
89-
npx prism path/to/your/openapi.yml
89+
npx prism mock path/to/your/openapi.yml
9090
```
9191

9292
```bash
@@ -121,5 +121,5 @@ You can release to package managers by using [the `Publish PyPI` GitHub action](
121121

122122
### Publish manually
123123

124-
If you need to manually release a package, you can run the `bin/publish-pypi` script with an `PYPI_TOKEN` set on
124+
If you need to manually release a package, you can run the `bin/publish-pypi` script with a `PYPI_TOKEN` set on
125125
the environment.

‎README.md‎

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The Maisa Python library provides convenient access to the Maisa REST API from a
66
application. The library includes type definitions for all request params and response fields,
77
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
88

9+
It is generated with [Stainless](https://www.stainlessapi.com/).
10+
911
## Documentation
1012

1113
The REST API documentation can be found [on docs.maisa.ai](https://docs.maisa.ai/). The full API of this library can be found in [api.md](api.md).
@@ -22,13 +24,9 @@ pip install --pre maisa
2224
The full API of this library can be found in [api.md](api.md).
2325

2426
```python
25-
import os
2627
from maisa import Maisa
2728

28-
client = Maisa(
29-
# This is the default and can be omitted
30-
api_key=os.environ.get("MAISA_API_KEY"),
31-
)
29+
client = Maisa()
3230

3331
text_summary = client.capabilities.summarize(
3432
text="Example long text...",
@@ -46,14 +44,10 @@ so that your API Key is not stored in source control.
4644
Simply import `AsyncMaisa` instead of `Maisa` and use `await` with each API call:
4745

4846
```python
49-
import os
5047
import asyncio
5148
from maisa import AsyncMaisa
5249

53-
client = AsyncMaisa(
54-
# This is the default and can be omitted
55-
api_key=os.environ.get("MAISA_API_KEY"),
56-
)
50+
client = AsyncMaisa()
5751

5852

5953
async def main() -> None:
@@ -70,10 +64,10 @@ Functionality between the synchronous and asynchronous clients is otherwise iden
7064

7165
## Using types
7266

73-
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev), which provide helper methods for things like:
67+
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
7468

75-
- Serializing back into JSON, `model.model_dump_json(indent=2, exclude_unset=True)`
76-
- Converting to a dictionary, `model.model_dump(exclude_unset=True)`
69+
- Serializing back into JSON, `model.to_json()`
70+
- Converting to a dictionary, `model.to_dict()`
7771

7872
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
7973

@@ -235,6 +229,41 @@ with client.capabilities.with_streaming_response.summarize(
235229

236230
The context manager is required so that the response will reliably be closed.
237231

232+
### Making custom/undocumented requests
233+
234+
This library is typed for convenient access the documented API.
235+
236+
If you need to access undocumented endpoints, params, or response properties, the library can still be used.
237+
238+
#### Undocumented endpoints
239+
240+
To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
241+
http verbs. Options on the client will be respected (such as retries) will be respected when making this
242+
request.
243+
244+
```py
245+
import httpx
246+
247+
response = client.post(
248+
"/foo",
249+
cast_to=httpx.Response,
250+
body={"my_param": True},
251+
)
252+
253+
print(response.headers.get("x-foo"))
254+
```
255+
256+
#### Undocumented request params
257+
258+
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
259+
options.
260+
261+
#### Undocumented response properties
262+
263+
To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
264+
can also get all the extra fields on the Pydantic model as a dict with
265+
[`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
266+
238267
### Configuring the HTTP client
239268

240269
You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
@@ -244,13 +273,12 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
244273
- Additional [advanced](https://www.python-httpx.org/advanced/#client-instances) functionality
245274

246275
```python
247-
import httpx
248-
from maisa import Maisa
276+
from maisa import Maisa, DefaultHttpxClient
249277

250278
client = Maisa(
251279
# Or use the `MAISA_BASE_URL` env var
252280
base_url="http://my.test.server.example.com:8083",
253-
http_client=httpx.Client(
281+
http_client=DefaultHttpxClient(
254282
proxies="http://my.test.proxy.example.com",
255283
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
256284
),

‎api.md‎

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,43 @@ Methods:
3434

3535
- <code title="post /v1/models/embeddings">client.models.embeddings.<a href="./src/maisa/resources/models/embeddings.py">create</a>(\*\*<a href="src/maisa/types/models/embedding_create_params.py">params</a>) -> <a href="./src/maisa/types/models/embeddings.py">Embeddings</a></code>
3636

37-
## RerankResource
37+
# Kpu
3838

3939
Types:
4040

4141
```python
42-
from maisa.types.models import Rerank
42+
from maisa.types import KpuRunResponse
4343
```
4444

4545
Methods:
4646

47-
- <code title="post /v1/models/rerank">client.models.rerank.<a href="./src/maisa/resources/models/rerank.py">create</a>(\*\*<a href="src/maisa/types/models/rerank_create_params.py">params</a>) -> <a href="./src/maisa/types/models/rerank.py">Rerank</a></code>
47+
- <code title="post /v1/kpu/run">client.kpu.<a href="./src/maisa/resources/kpu.py">run</a>(\*\*<a href="src/maisa/types/kpu_run_params.py">params</a>) -> <a href="./src/maisa/types/kpu_run_response.py">object</a></code>
4848

49-
# Kpu
49+
# FileInterpreter
50+
51+
## FromPdf
5052

5153
Types:
5254

5355
```python
54-
from maisa.types import KpuRunResponse
56+
from maisa.types.file_interpreter import FromPdfCreateResponse
5557
```
5658

5759
Methods:
5860

59-
- <code title="post /v1/kpu/run">client.kpu.<a href="./src/maisa/resources/kpu.py">run</a>(\*\*<a href="src/maisa/types/kpu_run_params.py">params</a>) -> <a href="./src/maisa/types/kpu_run_response.py">KpuRunResponse</a></code>
60-
61-
# FileInterpreter
61+
- <code title="post /v1/file-interpreter/from-pdf">client.file_interpreter.from_pdf.<a href="./src/maisa/resources/file_interpreter/from_pdf.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_pdf_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_pdf_create_response.py">object</a></code>
6262

63-
## FromPdf
63+
## FromPdfScanned
6464

6565
Types:
6666

6767
```python
68-
from maisa.types.file_interpreter import FromPdfCreateResponse
68+
from maisa.types.file_interpreter import FromPdfScannedCreateResponse
6969
```
7070

7171
Methods:
7272

73-
- <code title="post /v1/file-interpreter/from-pdf">client.file_interpreter.from_pdf.<a href="./src/maisa/resources/file_interpreter/from_pdf.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_pdf_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_pdf_create_response.py">object</a></code>
73+
- <code title="post /v1/file-interpreter/from-pdf-scanned">client.file_interpreter.from_pdf_scanned.<a href="./src/maisa/resources/file_interpreter/from_pdf_scanned.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_pdf_scanned_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_pdf_scanned_create_response.py">object</a></code>
7474

7575
## FromDocx
7676

@@ -96,17 +96,17 @@ Methods:
9696

9797
- <code title="post /v1/file-interpreter/from-html">client.file_interpreter.from_html.<a href="./src/maisa/resources/file_interpreter/from_html.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_html_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_html_create_response.py">object</a></code>
9898

99-
## FromImageResource
99+
## FromImage
100100

101101
Types:
102102

103103
```python
104-
from maisa.types.file_interpreter import FromImage
104+
from maisa.types.file_interpreter import FromImageCreateResponse
105105
```
106106

107107
Methods:
108108

109-
- <code title="post /v1/file-interpreter/from-image">client.file_interpreter.from_image.<a href="./src/maisa/resources/file_interpreter/from_image.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_image_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_image.py">FromImage</a></code>
109+
- <code title="post /v1/file-interpreter/from-image">client.file_interpreter.from_image.<a href="./src/maisa/resources/file_interpreter/from_image.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_image_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_image_create_response.py">object</a></code>
110110

111111
## FromAudio
112112

@@ -119,17 +119,3 @@ from maisa.types.file_interpreter import FromAudioCreateResponse
119119
Methods:
120120

121121
- <code title="post /v1/file-interpreter/from-audio">client.file_interpreter.from_audio.<a href="./src/maisa/resources/file_interpreter/from_audio.py">create</a>(\*\*<a href="src/maisa/types/file_interpreter/from_audio_create_params.py">params</a>) -> <a href="./src/maisa/types/file_interpreter/from_audio_create_response.py">object</a></code>
122-
123-
# Mainet
124-
125-
## SearchResource
126-
127-
Types:
128-
129-
```python
130-
from maisa.types.mainet import Search
131-
```
132-
133-
Methods:
134-
135-
- <code title="post /v1/mainet/search">client.mainet.search.<a href="./src/maisa/resources/mainet/search.py">create</a>(\*\*<a href="src/maisa/types/mainet/search_create_params.py">params</a>) -> <a href="./src/maisa/types/mainet/search.py">Search</a></code>

‎pyproject.toml‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
name = "maisa"
33
version = "0.1.0-alpha.4"
44
description = "The official Python library for the Maisa API"
5-
readme = "README.md"
5+
dynamic = ["readme"]
66
license = "Apache-2.0"
77
authors = [
8-
{ name = "Maisa", email = "support@clibrain.com" },
8+
{ name = "Maisa", email = "support@maisa.ai" },
99
]
1010
dependencies = [
1111
"httpx>=0.23.0, <1",
@@ -48,7 +48,7 @@ Repository = "https://github.com/maisaai/python-sdk"
4848
managed = true
4949
# version pins are in requirements-dev.lock
5050
dev-dependencies = [
51-
"pyright",
51+
"pyright>=1.1.359",
5252
"mypy",
5353
"respx",
5454
"pytest",
@@ -88,7 +88,7 @@ typecheck = { chain = [
8888
"typecheck:mypy" = "mypy ."
8989

9090
[build-system]
91-
requires = ["hatchling"]
91+
requires = ["hatchling", "hatch-fancy-pypi-readme"]
9292
build-backend = "hatchling.build"
9393

9494
[tool.hatch.build]
@@ -99,6 +99,17 @@ include = [
9999
[tool.hatch.build.targets.wheel]
100100
packages = ["src/maisa"]
101101

102+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
103+
content-type = "text/markdown"
104+
105+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
106+
path = "README.md"
107+
108+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
109+
# replace relative links with absolute links
110+
pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
111+
replacement = '[\1](https://github.com/maisaai/python-sdk/tree/main/\g<2>)'
112+
102113
[tool.black]
103114
line-length = 120
104115
target-version = ["py37"]
@@ -130,6 +141,7 @@ reportImplicitOverride = true
130141
reportImportCycles = false
131142
reportPrivateUsage = false
132143

144+
133145
[tool.ruff]
134146
line-length = 120
135147
output-format = "grouped"
@@ -149,7 +161,9 @@ select = [
149161
"T201",
150162
"T203",
151163
# misuse of typing.TYPE_CHECKING
152-
"TCH004"
164+
"TCH004",
165+
# import rules
166+
"TID251",
153167
]
154168
ignore = [
155169
# mutable defaults
@@ -165,6 +179,9 @@ ignore-init-module-imports = true
165179
[tool.ruff.format]
166180
docstring-code-format = true
167181

182+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
183+
"functools.lru_cache".msg = "This function does not retain type information for the wrapped function's arguments; The `lru_cache` function from `_utils` should be used instead"
184+
168185
[tool.ruff.lint.isort]
169186
length-sort = true
170187
length-sort-straight = true

‎requirements-dev.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pydantic==2.4.2
6363
# via maisa
6464
pydantic-core==2.10.1
6565
# via pydantic
66-
pyright==1.1.351
66+
pyright==1.1.359
6767
pytest==7.1.1
6868
# via pytest-asyncio
6969
pytest-asyncio==0.21.1

‎src/maisa/__init__.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
# File generated from our OpenAPI spec by Stainless.
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
from . import types
4-
from ._types import NoneType, Transport, ProxiesTypes
4+
from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes
55
from ._utils import file_from_path
66
from ._client import Maisa, Client, Stream, Timeout, Transport, AsyncMaisa, AsyncClient, AsyncStream, RequestOptions
77
from ._models import BaseModel
88
from ._version import __title__, __version__
99
from ._response import APIResponse as APIResponse, AsyncAPIResponse as AsyncAPIResponse
10+
from ._constants import DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES, DEFAULT_CONNECTION_LIMITS
1011
from ._exceptions import (
1112
APIError,
1213
MaisaError,
@@ -23,6 +24,7 @@
2324
UnprocessableEntityError,
2425
APIResponseValidationError,
2526
)
27+
from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient
2628
from ._utils._logs import setup_logging as _setup_logging
2729

2830
__all__ = [
@@ -32,6 +34,8 @@
3234
"NoneType",
3335
"Transport",
3436
"ProxiesTypes",
37+
"NotGiven",
38+
"NOT_GIVEN",
3539
"MaisaError",
3640
"APIError",
3741
"APIStatusError",
@@ -56,6 +60,11 @@
5660
"AsyncMaisa",
5761
"file_from_path",
5862
"BaseModel",
63+
"DEFAULT_TIMEOUT",
64+
"DEFAULT_MAX_RETRIES",
65+
"DEFAULT_CONNECTION_LIMITS",
66+
"DefaultHttpxClient",
67+
"DefaultAsyncHttpxClient",
5968
]
6069

6170
_setup_logging()

0 commit comments

Comments
 (0)