# Client

The ByteKit Python SDK provides two client classes for making API requests.

Install the SDK, create a client, run a scrape and read the markdown:

```python
# pip install bytekit-sdk   (import name: bytekit)
import os

from bytekit import ByteKit
from bytekit.models import ScrapeSuccessEnvelope

client = ByteKit(api_key=os.environ["BYTEKIT_API_KEY"])
result = client.scrape.create(url="https://example.com", formats=["markdown"])
if isinstance(result, ScrapeSuccessEnvelope):
    print(result.formats.markdown)
```

## Client

A class for keeping track of data related to the API

The following are accepted as keyword arguments and will be used to construct httpx Clients internally:

``base_url``: The base URL for the API, all requests are made to a relative path to this URL

``cookies``: A dictionary of cookies to be sent with every request

``headers``: A dictionary of headers to be sent with every request

``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded. A connection that never gets established at
all — DNS failure, refused connection, TLS handshake failure — raises its transport
sibling httpx.ConnectError instead. Neither is caught by this SDK: both propagate to the
caller, on the generated operations and on ``AuthenticatedClient.search`` alike.

``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.

``follow_redirects``: Whether or not to follow redirects. Default value is False.

``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.

Attributes:
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
argument to the constructor.
Explicit constructor arguments always win over these defaults (explicit arg > default).

### with_headers

```python
with_headers(headers: dict[str, str]) -> 'Client'
```

Get a new client matching this one with additional headers

### with_cookies

```python
with_cookies(cookies: dict[str, str]) -> 'Client'
```

Get a new client matching this one with additional cookies

### with_timeout

```python
with_timeout(timeout: httpx.Timeout) -> 'Client'
```

Get a new client matching this one with a new timeout configuration

### set_httpx_client

```python
set_httpx_client(client: httpx.Client) -> Self
```

Manually set the underlying httpx.Client

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.

### get_httpx_client

```python
get_httpx_client() -> httpx.Client
```

Get the underlying httpx.Client, constructing a new one if not previously set

### set_async_httpx_client

```python
set_async_httpx_client(async_client: httpx.AsyncClient) -> Self
```

Manually set the underlying httpx.AsyncClient

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.

A client set here is YOURS to manage: the SDK never rebuilds or closes it, even if
it is later used from a different event loop. Clients the SDK constructs itself are
rebuilt automatically when the running event loop changes.

### get_async_httpx_client

```python
get_async_httpx_client() -> httpx.AsyncClient
```

Get the underlying httpx.AsyncClient, constructing a new one if not previously set

## AuthenticatedClient

A Client which has been authenticated for use on secured endpoints

The following are accepted as keyword arguments and will be used to construct httpx Clients internally:

``base_url``: The base URL for the API, all requests are made to a relative path to this URL

``cookies``: A dictionary of cookies to be sent with every request

``headers``: A dictionary of headers to be sent with every request

``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded. A connection that never gets established at
all — DNS failure, refused connection, TLS handshake failure — raises its transport
sibling httpx.ConnectError instead. Neither is caught by this SDK: both propagate to the
caller, on the generated operations and on ``AuthenticatedClient.search`` alike.

``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.

``follow_redirects``: Whether or not to follow redirects. Default value is False.

``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.

Attributes:
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
argument to the constructor.
Explicit constructor arguments always win over these defaults (explicit arg > default).
token: The token to use for authentication. KEYWORD-ONLY.
prefix: The prefix to use for the Authorization header. KEYWORD-ONLY.
auth_header_name: The name of the Authorization header. KEYWORD-ONLY.
All three are keyword-only so that the pre-0.3.0 positional call
``AuthenticatedClient(base_url, token)`` raises TypeError instead of
silently binding the base URL to ``token`` and the API key to ``prefix``.

### search

```python
search(query: str, type: Optional[Union['CreateSearchBodyType', Literal['web', 'news', 'images']]] = None, limit: Optional[int] = None, country: Optional[str] = None, language: Optional[str] = None, date_range: Optional[Union['CreateSearchBodyDateRange', Literal['any', 'hour', 'day', 'week', 'month', 'year']]] = None) -> 'CreateSearchResponse200'
```

Run a web search and return ranked organic results.

Thin, statically-declared delegate to the hand-written ``_search`` appended at the
bottom of this module; the full contract (argument semantics, the
``errors.UnexpectedStatus`` guarantee) is documented there.

### with_headers

```python
with_headers(headers: dict[str, str]) -> 'AuthenticatedClient'
```

Get a new client matching this one with additional headers

### with_cookies

```python
with_cookies(cookies: dict[str, str]) -> 'AuthenticatedClient'
```

Get a new client matching this one with additional cookies

### with_timeout

```python
with_timeout(timeout: httpx.Timeout) -> 'AuthenticatedClient'
```

Get a new client matching this one with a new timeout configuration

### set_httpx_client

```python
set_httpx_client(client: httpx.Client) -> Self
```

Manually set the underlying httpx.Client

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.

### get_httpx_client

```python
get_httpx_client() -> httpx.Client
```

Get the underlying httpx.Client, constructing a new one if not previously set

### set_async_httpx_client

```python
set_async_httpx_client(async_client: httpx.AsyncClient) -> Self
```

Manually set the underlying httpx.AsyncClient

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.

A client set here is YOURS to manage: the SDK never rebuilds or closes it, even if
it is later used from a different event loop. Clients the SDK constructs itself are
rebuilt automatically when the running event loop changes.

### get_async_httpx_client

```python
get_async_httpx_client() -> httpx.AsyncClient
```

Get the underlying httpx.AsyncClient, constructing a new one if not previously set