# Python

## Install

```bash
pip install scispace
```

Requires Python 3.9 or later.

## Configure

```python
from scispace import Scispace

client = Scispace(
    api_key=None,            # defaults to SCISPACE_API_KEY
    timeout=60.0,            # seconds, per request
    max_retries=4,           # on 429 and 5xx
    api_version="2026-08-01",
)
```

## Minimal example

```python
search = client.searches.create(
    query="How does climate change affect biodiversity?",
    depth="standard",
).wait()

print(search.answer.text)
```

## Ergonomics

**Waiting on async resources**

```python
extraction = client.extractions.create(
    schema_id="exsc_2hq7bnv6ld",
    document_ids=["doc_8ba2f01c47", "doc_5aa30bd812"],
).wait(timeout=900)
```

**Auto-pagination**

```python
for paper in client.papers.list(query="transformer architecture"):
    print(paper.doi)          # fetches further pages as needed
```

**Streaming**

```python
with client.chats.messages.stream(
    chat_id="chat_1r8eaidwoq",
    content="What datasets were used?",
) as stream:
    for event in stream:
        if event.type == "message.delta":
            print(event.delta, end="", flush=True)
        elif event.type == "citation.added":
            print(f"\n[{event.citation.index}] p.{event.citation.locations[0].page}")
    message = stream.get_final_message()
```

**Errors**

```python
from scispace import (
    ScispaceError,
    InvalidRequestError,
    AuthenticationError,
    PermissionError,
    NotFoundError,
    RateLimitError,
    InsufficientCreditsError,
    APIError,
)

try:
    client.searches.create(query="")
except InvalidRequestError as e:
    print(e.code, e.param, e.request_id)
except InsufficientCreditsError:
    print("Out of credits — top up before retrying")
```

Every exception carries `code`, `param`, `request_id`, and `status_code`.

## Async client

```python
from scispace import AsyncScispace

client = AsyncScispace()

search = await (
    await client.searches.create(query="How does climate change affect biodiversity?")
).wait()
```

Identical surface, `async`/`await` throughout, with `async for` on paginators and streams.

## Full reference

Generated API surface: `https://docs.scispace.com/sdks/python/reference`.

## Related

sdks-overview · errors-and-retries · streaming-deep-review
