Skip to content

Commit cbcd935

Browse files
authored
Merge pull request #25 from perplexityai/release-please--branches--main--changes--next
release: 0.22.1
2 parents fecc150 + 537d256 commit cbcd935

File tree

10 files changed

+195
-45
lines changed

10 files changed

+195
-45
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.22.0"
2+
".": "0.22.1"
33
}

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 0.22.1 (2025-12-16)
4+
5+
Full Changelog: [v0.22.0...v0.22.1](https://github.com/perplexityai/perplexity-py/compare/v0.22.0...v0.22.1)
6+
7+
### Bug Fixes
8+
9+
* **types:** allow pyright to infer TypedDict types within SequenceNotStr ([1dae6e5](https://github.com/perplexityai/perplexity-py/commit/1dae6e56a918d3ac6cbc38accd3058c169199515))
10+
11+
12+
### Chores
13+
14+
* add missing docstrings ([be56ae3](https://github.com/perplexityai/perplexity-py/commit/be56ae34c5342b345e53b706c006f6a873e1db74))
15+
* **internal:** add missing files argument to base client ([a2599a9](https://github.com/perplexityai/perplexity-py/commit/a2599a9261bf65ee59f611918b05eee8b7c55ead))
16+
* speedup initial import ([2e54d11](https://github.com/perplexityai/perplexity-py/commit/2e54d1119537403fe72903a25cba1ef75fcb274f))
17+
318
## 0.22.0 (2025-12-05)
419

520
Full Changelog: [v0.21.0...v0.22.0](https://github.com/perplexityai/perplexity-py/compare/v0.21.0...v0.22.0)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "perplexityai"
3-
version = "0.22.0"
3+
version = "0.22.1"
44
description = "The official Python library for the perplexity API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/perplexity/_base_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,9 +1247,12 @@ def patch(
12471247
*,
12481248
cast_to: Type[ResponseT],
12491249
body: Body | None = None,
1250+
files: RequestFiles | None = None,
12501251
options: RequestOptions = {},
12511252
) -> ResponseT:
1252-
opts = FinalRequestOptions.construct(method="patch", url=path, json_data=body, **options)
1253+
opts = FinalRequestOptions.construct(
1254+
method="patch", url=path, json_data=body, files=to_httpx_files(files), **options
1255+
)
12531256
return self.request(cast_to, opts)
12541257

12551258
def put(
@@ -1767,9 +1770,12 @@ async def patch(
17671770
*,
17681771
cast_to: Type[ResponseT],
17691772
body: Body | None = None,
1773+
files: RequestFiles | None = None,
17701774
options: RequestOptions = {},
17711775
) -> ResponseT:
1772-
opts = FinalRequestOptions.construct(method="patch", url=path, json_data=body, **options)
1776+
opts = FinalRequestOptions.construct(
1777+
method="patch", url=path, json_data=body, files=to_httpx_files(files), **options
1778+
)
17731779
return await self.request(cast_to, opts)
17741780

17751781
async def put(

src/perplexity/_client.py

Lines changed: 142 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Any, Mapping
6+
from typing import TYPE_CHECKING, Any, Mapping
77
from typing_extensions import Self, override
88

99
import httpx
@@ -20,17 +20,21 @@
2020
not_given,
2121
)
2222
from ._utils import is_given, get_async_library
23+
from ._compat import cached_property
2324
from ._version import __version__
24-
from .resources import search
2525
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
2626
from ._exceptions import APIStatusError, PerplexityError
2727
from ._base_client import (
2828
DEFAULT_MAX_RETRIES,
2929
SyncAPIClient,
3030
AsyncAPIClient,
3131
)
32-
from .resources.chat import chat
33-
from .resources.async_ import async_
32+
33+
if TYPE_CHECKING:
34+
from .resources import chat, async_, search
35+
from .resources.search import SearchResource, AsyncSearchResource
36+
from .resources.chat.chat import ChatResource, AsyncChatResource
37+
from .resources.async_.async_ import AsyncResource, AsyncAsyncResource
3438

3539
__all__ = [
3640
"Timeout",
@@ -45,12 +49,6 @@
4549

4650

4751
class Perplexity(SyncAPIClient):
48-
chat: chat.ChatResource
49-
search: search.SearchResource
50-
async_: async_.AsyncResource
51-
with_raw_response: PerplexityWithRawResponse
52-
with_streaming_response: PerplexityWithStreamedResponse
53-
5452
# client options
5553
api_key: str
5654

@@ -107,11 +105,31 @@ def __init__(
107105

108106
self._default_stream_cls = Stream
109107

110-
self.chat = chat.ChatResource(self)
111-
self.search = search.SearchResource(self)
112-
self.async_ = async_.AsyncResource(self)
113-
self.with_raw_response = PerplexityWithRawResponse(self)
114-
self.with_streaming_response = PerplexityWithStreamedResponse(self)
108+
@cached_property
109+
def chat(self) -> ChatResource:
110+
from .resources.chat import ChatResource
111+
112+
return ChatResource(self)
113+
114+
@cached_property
115+
def search(self) -> SearchResource:
116+
from .resources.search import SearchResource
117+
118+
return SearchResource(self)
119+
120+
@cached_property
121+
def async_(self) -> AsyncResource:
122+
from .resources.async_ import AsyncResource
123+
124+
return AsyncResource(self)
125+
126+
@cached_property
127+
def with_raw_response(self) -> PerplexityWithRawResponse:
128+
return PerplexityWithRawResponse(self)
129+
130+
@cached_property
131+
def with_streaming_response(self) -> PerplexityWithStreamedResponse:
132+
return PerplexityWithStreamedResponse(self)
115133

116134
@property
117135
@override
@@ -219,12 +237,6 @@ def _make_status_error(
219237

220238

221239
class AsyncPerplexity(AsyncAPIClient):
222-
chat: chat.AsyncChatResource
223-
search: search.AsyncSearchResource
224-
async_: async_.AsyncAsyncResource
225-
with_raw_response: AsyncPerplexityWithRawResponse
226-
with_streaming_response: AsyncPerplexityWithStreamedResponse
227-
228240
# client options
229241
api_key: str
230242

@@ -281,11 +293,31 @@ def __init__(
281293

282294
self._default_stream_cls = AsyncStream
283295

284-
self.chat = chat.AsyncChatResource(self)
285-
self.search = search.AsyncSearchResource(self)
286-
self.async_ = async_.AsyncAsyncResource(self)
287-
self.with_raw_response = AsyncPerplexityWithRawResponse(self)
288-
self.with_streaming_response = AsyncPerplexityWithStreamedResponse(self)
296+
@cached_property
297+
def chat(self) -> AsyncChatResource:
298+
from .resources.chat import AsyncChatResource
299+
300+
return AsyncChatResource(self)
301+
302+
@cached_property
303+
def search(self) -> AsyncSearchResource:
304+
from .resources.search import AsyncSearchResource
305+
306+
return AsyncSearchResource(self)
307+
308+
@cached_property
309+
def async_(self) -> AsyncAsyncResource:
310+
from .resources.async_ import AsyncAsyncResource
311+
312+
return AsyncAsyncResource(self)
313+
314+
@cached_property
315+
def with_raw_response(self) -> AsyncPerplexityWithRawResponse:
316+
return AsyncPerplexityWithRawResponse(self)
317+
318+
@cached_property
319+
def with_streaming_response(self) -> AsyncPerplexityWithStreamedResponse:
320+
return AsyncPerplexityWithStreamedResponse(self)
289321

290322
@property
291323
@override
@@ -393,31 +425,103 @@ def _make_status_error(
393425

394426

395427
class PerplexityWithRawResponse:
428+
_client: Perplexity
429+
396430
def __init__(self, client: Perplexity) -> None:
397-
self.chat = chat.ChatResourceWithRawResponse(client.chat)
398-
self.search = search.SearchResourceWithRawResponse(client.search)
399-
self.async_ = async_.AsyncResourceWithRawResponse(client.async_)
431+
self._client = client
432+
433+
@cached_property
434+
def chat(self) -> chat.ChatResourceWithRawResponse:
435+
from .resources.chat import ChatResourceWithRawResponse
436+
437+
return ChatResourceWithRawResponse(self._client.chat)
438+
439+
@cached_property
440+
def search(self) -> search.SearchResourceWithRawResponse:
441+
from .resources.search import SearchResourceWithRawResponse
442+
443+
return SearchResourceWithRawResponse(self._client.search)
444+
445+
@cached_property
446+
def async_(self) -> async_.AsyncResourceWithRawResponse:
447+
from .resources.async_ import AsyncResourceWithRawResponse
448+
449+
return AsyncResourceWithRawResponse(self._client.async_)
400450

401451

402452
class AsyncPerplexityWithRawResponse:
453+
_client: AsyncPerplexity
454+
403455
def __init__(self, client: AsyncPerplexity) -> None:
404-
self.chat = chat.AsyncChatResourceWithRawResponse(client.chat)
405-
self.search = search.AsyncSearchResourceWithRawResponse(client.search)
406-
self.async_ = async_.AsyncAsyncResourceWithRawResponse(client.async_)
456+
self._client = client
457+
458+
@cached_property
459+
def chat(self) -> chat.AsyncChatResourceWithRawResponse:
460+
from .resources.chat import AsyncChatResourceWithRawResponse
461+
462+
return AsyncChatResourceWithRawResponse(self._client.chat)
463+
464+
@cached_property
465+
def search(self) -> search.AsyncSearchResourceWithRawResponse:
466+
from .resources.search import AsyncSearchResourceWithRawResponse
467+
468+
return AsyncSearchResourceWithRawResponse(self._client.search)
469+
470+
@cached_property
471+
def async_(self) -> async_.AsyncAsyncResourceWithRawResponse:
472+
from .resources.async_ import AsyncAsyncResourceWithRawResponse
473+
474+
return AsyncAsyncResourceWithRawResponse(self._client.async_)
407475

408476

409477
class PerplexityWithStreamedResponse:
478+
_client: Perplexity
479+
410480
def __init__(self, client: Perplexity) -> None:
411-
self.chat = chat.ChatResourceWithStreamingResponse(client.chat)
412-
self.search = search.SearchResourceWithStreamingResponse(client.search)
413-
self.async_ = async_.AsyncResourceWithStreamingResponse(client.async_)
481+
self._client = client
482+
483+
@cached_property
484+
def chat(self) -> chat.ChatResourceWithStreamingResponse:
485+
from .resources.chat import ChatResourceWithStreamingResponse
486+
487+
return ChatResourceWithStreamingResponse(self._client.chat)
488+
489+
@cached_property
490+
def search(self) -> search.SearchResourceWithStreamingResponse:
491+
from .resources.search import SearchResourceWithStreamingResponse
492+
493+
return SearchResourceWithStreamingResponse(self._client.search)
494+
495+
@cached_property
496+
def async_(self) -> async_.AsyncResourceWithStreamingResponse:
497+
from .resources.async_ import AsyncResourceWithStreamingResponse
498+
499+
return AsyncResourceWithStreamingResponse(self._client.async_)
414500

415501

416502
class AsyncPerplexityWithStreamedResponse:
503+
_client: AsyncPerplexity
504+
417505
def __init__(self, client: AsyncPerplexity) -> None:
418-
self.chat = chat.AsyncChatResourceWithStreamingResponse(client.chat)
419-
self.search = search.AsyncSearchResourceWithStreamingResponse(client.search)
420-
self.async_ = async_.AsyncAsyncResourceWithStreamingResponse(client.async_)
506+
self._client = client
507+
508+
@cached_property
509+
def chat(self) -> chat.AsyncChatResourceWithStreamingResponse:
510+
from .resources.chat import AsyncChatResourceWithStreamingResponse
511+
512+
return AsyncChatResourceWithStreamingResponse(self._client.chat)
513+
514+
@cached_property
515+
def search(self) -> search.AsyncSearchResourceWithStreamingResponse:
516+
from .resources.search import AsyncSearchResourceWithStreamingResponse
517+
518+
return AsyncSearchResourceWithStreamingResponse(self._client.search)
519+
520+
@cached_property
521+
def async_(self) -> async_.AsyncAsyncResourceWithStreamingResponse:
522+
from .resources.async_ import AsyncAsyncResourceWithStreamingResponse
523+
524+
return AsyncAsyncResourceWithStreamingResponse(self._client.async_)
421525

422526

423527
Client = Perplexity

src/perplexity/_types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ class HttpxSendArgs(TypedDict, total=False):
243243
if TYPE_CHECKING:
244244
# This works because str.__contains__ does not accept object (either in typeshed or at runtime)
245245
# https://github.com/hauntsaninja/useful_types/blob/5e9710f3875107d068e7679fd7fec9cfab0eff3b/useful_types/__init__.py#L285
246+
#
247+
# Note: index() and count() methods are intentionally omitted to allow pyright to properly
248+
# infer TypedDict types when dict literals are used in lists assigned to SequenceNotStr.
246249
class SequenceNotStr(Protocol[_T_co]):
247250
@overload
248251
def __getitem__(self, index: SupportsIndex, /) -> _T_co: ...
@@ -251,8 +254,6 @@ def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ...
251254
def __contains__(self, value: object, /) -> bool: ...
252255
def __len__(self) -> int: ...
253256
def __iter__(self) -> Iterator[_T_co]: ...
254-
def index(self, value: Any, start: int = 0, stop: int = ..., /) -> int: ...
255-
def count(self, value: Any, /) -> int: ...
256257
def __reversed__(self) -> Iterator[_T_co]: ...
257258
else:
258259
# just point this to a normal `Sequence` at runtime to avoid having to special case

src/perplexity/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "perplexity"
4-
__version__ = "0.22.0" # x-release-please-version
4+
__version__ = "0.22.1" # x-release-please-version

src/perplexity/types/shared/chat_message_input.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,30 @@ class ContentStructuredContentChatMessageContentVideoChunk(BaseModel):
111111

112112

113113
class ReasoningStepExecutePython(BaseModel):
114+
"""Code generation step details wrapper class"""
115+
114116
code: str
115117

116118
result: str
117119

118120

119121
class ReasoningStepFetchURLContent(BaseModel):
122+
"""Fetch url content step details wrapper class"""
123+
120124
contents: List[APIPublicSearchResult]
121125

122126

123127
class ReasoningStepWebSearch(BaseModel):
128+
"""Web search step details wrapper class"""
129+
124130
search_keywords: List[str]
125131

126132
search_results: List[APIPublicSearchResult]
127133

128134

129135
class ReasoningStep(BaseModel):
136+
"""Reasoning step wrapper class"""
137+
130138
thought: str
131139

132140
execute_python: Optional[ReasoningStepExecutePython] = None

src/perplexity/types/shared/chat_message_output.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,30 @@ class ContentStructuredContentChatMessageContentVideoChunk(BaseModel):
111111

112112

113113
class ReasoningStepExecutePython(BaseModel):
114+
"""Code generation step details wrapper class"""
115+
114116
code: str
115117

116118
result: str
117119

118120

119121
class ReasoningStepFetchURLContent(BaseModel):
122+
"""Fetch url content step details wrapper class"""
123+
120124
contents: List[APIPublicSearchResult]
121125

122126

123127
class ReasoningStepWebSearch(BaseModel):
128+
"""Web search step details wrapper class"""
129+
124130
search_keywords: List[str]
125131

126132
search_results: List[APIPublicSearchResult]
127133

128134

129135
class ReasoningStep(BaseModel):
136+
"""Reasoning step wrapper class"""
137+
130138
thought: str
131139

132140
execute_python: Optional[ReasoningStepExecutePython] = None

0 commit comments

Comments
 (0)