Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.29.1"
".": "0.30.0"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 8
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-78325ecc9bdc8e9850866fcdd3be3d209b06f151059c774afc7e6005a1775f09.yml
openapi_spec_hash: 19a34c8ddd46f81dd0b0850af5ee42f3
config_hash: c3b93f1bb8fa365d5a83e83b7e13e6c4
configured_endpoints: 10
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-e5052719572f5155f4cf704d996e5c7a875700a16f68f2335975ea3d06140b17.yml
openapi_spec_hash: 97d9df5dc228bb6d71be54212bc5b600
config_hash: e09a1767e929614701fb498eaaac682d
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 0.30.0 (2026-02-23)

Full Changelog: [v0.29.1...v0.30.0](https://github.com/perplexityai/perplexity-py/compare/v0.29.1...v0.30.0)

### Features

* **api:** Add browser and sandbox API endpoints ([f5c3e58](https://github.com/perplexityai/perplexity-py/commit/f5c3e58836feb37a6b9ba366a55811513a8cd28c))
* **api:** manual updates ([a556321](https://github.com/perplexityai/perplexity-py/commit/a556321ac2ed946bfeccc9912dd20ee71349a34a))


### Chores

* **internal:** add request options to SSE classes ([b18a992](https://github.com/perplexityai/perplexity-py/commit/b18a992a0eedca20c38932809e1056dfb8c5b00e))
* **internal:** remove mock server code ([081b00d](https://github.com/perplexityai/perplexity-py/commit/081b00d6a86f95631caacd16a46ea91c8f6d97b9))
* update mock server docs ([d6f9a54](https://github.com/perplexityai/perplexity-py/commit/d6f9a5428ecb632baea8705f4eadc1225ba5a9fd))

## 0.29.1 (2026-02-12)

Full Changelog: [v0.29.0...v0.29.1](https://github.com/perplexityai/perplexity-py/compare/v0.29.0...v0.29.1)
Expand Down
7 changes: 0 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ $ pip install ./path-to-wheel-file.whl

## Running tests

Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```sh
# you will need npm installed
$ npx prism mock path/to/your/openapi.yml
```

```sh
$ ./scripts/test
```
Expand Down
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
```python
from perplexity.types import (
APIPublicSearchResult,
BrowserSessionResponse,
ChatMessageInput,
ChatMessageOutput,
Choice,
Expand Down Expand Up @@ -92,6 +93,15 @@ Methods:

- <code title="post /v1/contextualizedembeddings">client.contextualized_embeddings.<a href="./src/perplexity/resources/contextualized_embeddings.py">create</a>(\*\*<a href="src/perplexity/types/contextualized_embedding_create_params.py">params</a>) -> <a href="./src/perplexity/types/contextualized_embedding_create_response.py">ContextualizedEmbeddingCreateResponse</a></code>

# Browser

## Sessions

Methods:

- <code title="post /v1/browser/sessions">client.browser.sessions.<a href="./src/perplexity/resources/browser/sessions.py">create</a>() -> <a href="./src/perplexity/types/shared/browser_session_response.py">BrowserSessionResponse</a></code>
- <code title="delete /v1/browser/sessions/{session_id}">client.browser.sessions.<a href="./src/perplexity/resources/browser/sessions.py">delete</a>(session_id) -> None</code>

# Async

## Chat
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "perplexityai"
version = "0.29.1"
version = "0.30.0"
description = "The official Python library for the perplexity API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
41 changes: 0 additions & 41 deletions scripts/mock

This file was deleted.

46 changes: 0 additions & 46 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,7 @@ set -e

cd "$(dirname "$0")/.."

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

function prism_is_running() {
curl --silent "http://localhost:4010" >/dev/null 2>&1
}

kill_server_on_port() {
pids=$(lsof -t -i tcp:"$1" || echo "")
if [ "$pids" != "" ]; then
kill "$pids"
echo "Stopped $pids."
fi
}

function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}

if ! is_overriding_api_base_url && ! prism_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT

# Start the dev server
./scripts/mock --daemon
fi

if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo
echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}"
echo

exit 1
else
echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}"
echo
fi

export DEFER_PYDANTIC_BUILD=false

Expand Down
39 changes: 38 additions & 1 deletion src/perplexity/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
)

if TYPE_CHECKING:
from .resources import chat, async_, search, responses, embeddings, contextualized_embeddings
from .resources import chat, async_, search, browser, responses, embeddings, contextualized_embeddings
from .resources.search import SearchResource, AsyncSearchResource
from .resources.chat.chat import ChatResource, AsyncChatResource
from .resources.responses import ResponsesResource, AsyncResponsesResource
from .resources.embeddings import EmbeddingsResource, AsyncEmbeddingsResource
from .resources.async_.async_ import AsyncResource, AsyncAsyncResource
from .resources.browser.browser import BrowserResource, AsyncBrowserResource
from .resources.contextualized_embeddings import (
ContextualizedEmbeddingsResource,
AsyncContextualizedEmbeddingsResource,
Expand Down Expand Up @@ -141,6 +142,12 @@ def contextualized_embeddings(self) -> ContextualizedEmbeddingsResource:

return ContextualizedEmbeddingsResource(self)

@cached_property
def browser(self) -> BrowserResource:
from .resources.browser import BrowserResource

return BrowserResource(self)

@cached_property
def async_(self) -> AsyncResource:
from .resources.async_ import AsyncResource
Expand Down Expand Up @@ -347,6 +354,12 @@ def contextualized_embeddings(self) -> AsyncContextualizedEmbeddingsResource:

return AsyncContextualizedEmbeddingsResource(self)

@cached_property
def browser(self) -> AsyncBrowserResource:
from .resources.browser import AsyncBrowserResource

return AsyncBrowserResource(self)

@cached_property
def async_(self) -> AsyncAsyncResource:
from .resources.async_ import AsyncAsyncResource
Expand Down Expand Up @@ -502,6 +515,12 @@ def contextualized_embeddings(self) -> contextualized_embeddings.ContextualizedE

return ContextualizedEmbeddingsResourceWithRawResponse(self._client.contextualized_embeddings)

@cached_property
def browser(self) -> browser.BrowserResourceWithRawResponse:
from .resources.browser import BrowserResourceWithRawResponse

return BrowserResourceWithRawResponse(self._client.browser)

@cached_property
def async_(self) -> async_.AsyncResourceWithRawResponse:
from .resources.async_ import AsyncResourceWithRawResponse
Expand Down Expand Up @@ -547,6 +566,12 @@ def contextualized_embeddings(

return AsyncContextualizedEmbeddingsResourceWithRawResponse(self._client.contextualized_embeddings)

@cached_property
def browser(self) -> browser.AsyncBrowserResourceWithRawResponse:
from .resources.browser import AsyncBrowserResourceWithRawResponse

return AsyncBrowserResourceWithRawResponse(self._client.browser)

@cached_property
def async_(self) -> async_.AsyncAsyncResourceWithRawResponse:
from .resources.async_ import AsyncAsyncResourceWithRawResponse
Expand Down Expand Up @@ -592,6 +617,12 @@ def contextualized_embeddings(

return ContextualizedEmbeddingsResourceWithStreamingResponse(self._client.contextualized_embeddings)

@cached_property
def browser(self) -> browser.BrowserResourceWithStreamingResponse:
from .resources.browser import BrowserResourceWithStreamingResponse

return BrowserResourceWithStreamingResponse(self._client.browser)

@cached_property
def async_(self) -> async_.AsyncResourceWithStreamingResponse:
from .resources.async_ import AsyncResourceWithStreamingResponse
Expand Down Expand Up @@ -637,6 +668,12 @@ def contextualized_embeddings(

return AsyncContextualizedEmbeddingsResourceWithStreamingResponse(self._client.contextualized_embeddings)

@cached_property
def browser(self) -> browser.AsyncBrowserResourceWithStreamingResponse:
from .resources.browser import AsyncBrowserResourceWithStreamingResponse

return AsyncBrowserResourceWithStreamingResponse(self._client.browser)

@cached_property
def async_(self) -> async_.AsyncAsyncResourceWithStreamingResponse:
from .resources.async_ import AsyncAsyncResourceWithStreamingResponse
Expand Down
3 changes: 3 additions & 0 deletions src/perplexity/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
),
response=self.http_response,
client=cast(Any, self._client),
options=self._options,
),
)

Expand All @@ -162,6 +163,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
cast_to=extract_stream_chunk_type(self._stream_cls),
response=self.http_response,
client=cast(Any, self._client),
options=self._options,
),
)

Expand All @@ -175,6 +177,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
cast_to=cast_to,
response=self.http_response,
client=cast(Any, self._client),
options=self._options,
),
)

Expand Down
11 changes: 8 additions & 3 deletions src/perplexity/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import inspect
from types import TracebackType
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, AsyncIterator, cast
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, Optional, AsyncIterator, cast
from typing_extensions import Self, Protocol, TypeGuard, override, get_origin, runtime_checkable

import httpx
Expand All @@ -13,6 +13,7 @@

if TYPE_CHECKING:
from ._client import Perplexity, AsyncPerplexity
from ._models import FinalRequestOptions


_T = TypeVar("_T")
Expand All @@ -22,7 +23,7 @@ class Stream(Generic[_T]):
"""Provides the core interface to iterate over a synchronous stream response."""

response: httpx.Response

_options: Optional[FinalRequestOptions] = None
_decoder: SSEBytesDecoder

def __init__(
Expand All @@ -31,10 +32,12 @@ def __init__(
cast_to: type[_T],
response: httpx.Response,
client: Perplexity,
options: Optional[FinalRequestOptions] = None,
) -> None:
self.response = response
self._cast_to = cast_to
self._client = client
self._options = options
self._decoder = client._make_sse_decoder()
self._iterator = self.__stream__()

Expand Down Expand Up @@ -104,7 +107,7 @@ class AsyncStream(Generic[_T]):
"""Provides the core interface to iterate over an asynchronous stream response."""

response: httpx.Response

_options: Optional[FinalRequestOptions] = None
_decoder: SSEDecoder | SSEBytesDecoder

def __init__(
Expand All @@ -113,10 +116,12 @@ def __init__(
cast_to: type[_T],
response: httpx.Response,
client: AsyncPerplexity,
options: Optional[FinalRequestOptions] = None,
) -> None:
self.response = response
self._cast_to = cast_to
self._client = client
self._options = options
self._decoder = client._make_sse_decoder()
self._iterator = self.__stream__()

Expand Down
2 changes: 1 addition & 1 deletion src/perplexity/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "perplexity"
__version__ = "0.29.1" # x-release-please-version
__version__ = "0.30.0" # x-release-please-version
14 changes: 14 additions & 0 deletions src/perplexity/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
SearchResourceWithStreamingResponse,
AsyncSearchResourceWithStreamingResponse,
)
from .browser import (
BrowserResource,
AsyncBrowserResource,
BrowserResourceWithRawResponse,
AsyncBrowserResourceWithRawResponse,
BrowserResourceWithStreamingResponse,
AsyncBrowserResourceWithStreamingResponse,
)
from .responses import (
ResponsesResource,
AsyncResponsesResource,
Expand Down Expand Up @@ -80,6 +88,12 @@
"AsyncContextualizedEmbeddingsResourceWithRawResponse",
"ContextualizedEmbeddingsResourceWithStreamingResponse",
"AsyncContextualizedEmbeddingsResourceWithStreamingResponse",
"BrowserResource",
"AsyncBrowserResource",
"BrowserResourceWithRawResponse",
"AsyncBrowserResourceWithRawResponse",
"BrowserResourceWithStreamingResponse",
"AsyncBrowserResourceWithStreamingResponse",
"AsyncResource",
"AsyncAsyncResource",
"AsyncResourceWithRawResponse",
Expand Down
Loading