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
31 changes: 31 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow is triggered when a GitHub release is created.
# It can also be run manually to re-publish to PyPI in case it failed for some reason.
# You can run this workflow by navigating to https://www.github.com/mixedbread-ai/mixedbread-python/actions/workflows/publish-pypi.yml
name: Publish PyPI
on:
workflow_dispatch:

release:
types: [published]

jobs:
publish:
name: publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Rye
run: |
curl -sSf https://rye.astral.sh/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: '0.35.0'
RYE_INSTALL_OPTION: '--yes'

- name: Publish to PyPI
run: |
bash ./bin/publish-pypi
env:
PYPI_TOKEN: ${{ secrets.MIXEDBREAD_PYPI_TOKEN || secrets.PYPI_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release Doctor
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
release_doctor:
name: release doctor
runs-on: ubuntu-latest
if: github.repository == 'mixedbread-ai/mixedbread-python' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v4

- name: Check release environment
run: |
bash ./bin/check-release-environment
env:
PYPI_TOKEN: ${{ secrets.MIXEDBREAD_PYPI_TOKEN || secrets.PYPI_TOKEN }}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.1.0-alpha.11"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 30
configured_endpoints: 22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mixedbread%2Fmixedbread-a9b8728ee918c023a0e1458cfab7f26721d4ac851c533c6ce2f53411bc1576d1.yml
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```sh
$ pip install git+ssh://git@github.com/stainless-sdks/mixedbread-python.git
$ pip install git+ssh://git@github.com/mixedbread-ai/mixedbread-python.git
```

Alternatively, you can build from source and install the wheel file:
Expand Down Expand Up @@ -121,7 +121,7 @@ the changes aren't made through the automated pipeline, you may want to make rel

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/stainless-sdks/mixedbread-python/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.
You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/mixedbread-ai/mixedbread-python/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

Expand Down
123 changes: 89 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ It is generated with [Stainless](https://www.stainlessapi.com/).

## Documentation

The REST API documentation can be found on [docs.mixedbread.com](https://docs.mixedbread.com). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [mixedbread.ai](https://mixedbread.ai/docs). The full API of this library can be found in [api.md](api.md).

## Installation

```sh
# install from this staging repo
pip install git+ssh://git@github.com/stainless-sdks/mixedbread-python.git
# install from the production repo
pip install git+ssh://git@github.com/mixedbread-ai/mixedbread-python.git
```

> [!NOTE]
Expand All @@ -27,43 +27,43 @@ pip install git+ssh://git@github.com/stainless-sdks/mixedbread-python.git
The full API of this library can be found in [api.md](api.md).

```python
import os
from mixedbread import Mixedbread

client = Mixedbread(
api_key=os.environ.get("MXBAI_API_KEY"), # This is the default and can be omitted
# defaults to "production".
environment="environment_1",
environment="local",
)

file_object = client.files.create(
file=b"raw file contents",
)
print(file_object.id)
vector_store = client.vector_stores.create()
print(vector_store.id)
```

While you can provide an `api_key` keyword argument,
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
to add `API_KEY="My API Key"` to your `.env` file
to add `MXBAI_API_KEY="My API Key"` to your `.env` file
so that your API Key is not stored in source control.

## Async usage

Simply import `AsyncMixedbread` instead of `Mixedbread` and use `await` with each API call:

```python
import os
import asyncio
from mixedbread import AsyncMixedbread

client = AsyncMixedbread(
api_key=os.environ.get("MXBAI_API_KEY"), # This is the default and can be omitted
# defaults to "production".
environment="environment_1",
environment="local",
)


async def main() -> None:
file_object = await client.files.create(
file=b"raw file contents",
)
print(file_object.id)
vector_store = await client.vector_stores.create()
print(vector_store.id)


asyncio.run(main())
Expand All @@ -80,6 +80,71 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ

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`.

## Pagination

List methods in the Mixedbread API are paginated.

This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:

```python
from mixedbread import Mixedbread

client = Mixedbread()

all_vector_stores = []
# Automatically fetches more pages as needed.
for vector_store in client.vector_stores.list():
# Do something with vector_store here
all_vector_stores.append(vector_store)
print(all_vector_stores)
```

Or, asynchronously:

```python
import asyncio
from mixedbread import AsyncMixedbread

client = AsyncMixedbread()


async def main() -> None:
all_vector_stores = []
# Iterate through items across all pages, issuing requests as needed.
async for vector_store in client.vector_stores.list():
all_vector_stores.append(vector_store)
print(all_vector_stores)


asyncio.run(main())
```

Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:

```python
first_page = await client.vector_stores.list()
if first_page.has_next_page():
print(f"will fetch next page using these details: {first_page.next_page_info()}")
next_page = await first_page.get_next_page()
print(f"number of items we just fetched: {len(next_page.data)}")

# Remove `await` for non-async usage.
```

Or just work directly with the returned data:

```python
first_page = await client.vector_stores.list()

print(
f"the current start offset for this page: {first_page.pagination.offset}"
) # => "the current start offset for this page: 1"
for vector_store in first_page.data:
print(vector_store.id)

# Remove `await` for non-async usage.
```

## Handling errors

When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `mixedbread.APIConnectionError` is raised.
Expand All @@ -96,9 +161,7 @@ from mixedbread import Mixedbread
client = Mixedbread()

try:
client.files.create(
file=b"raw file contents",
)
client.vector_stores.create()
except mixedbread.APIConnectionError as e:
print("The server could not be reached")
print(e.__cause__) # an underlying Exception, likely raised within httpx.
Expand Down Expand Up @@ -141,9 +204,7 @@ client = Mixedbread(
)

# Or, configure per-request:
client.with_options(max_retries=5).files.create(
file=b"raw file contents",
)
client.with_options(max_retries=5).vector_stores.create()
```

### Timeouts
Expand All @@ -166,9 +227,7 @@ client = Mixedbread(
)

# Override per-request:
client.with_options(timeout=5.0).files.create(
file=b"raw file contents",
)
client.with_options(timeout=5.0).vector_stores.create()
```

On timeout, an `APITimeoutError` is thrown.
Expand Down Expand Up @@ -209,18 +268,16 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
from mixedbread import Mixedbread

client = Mixedbread()
response = client.files.with_raw_response.create(
file=b'raw file contents',
)
response = client.vector_stores.with_raw_response.create()
print(response.headers.get('X-My-Header'))

file = response.parse() # get the object that `files.create()` would have returned
print(file.id)
vector_store = response.parse() # get the object that `vector_stores.create()` would have returned
print(vector_store.id)
```

These methods return an [`APIResponse`](https://github.com/stainless-sdks/mixedbread-python/tree/main/src/mixedbread/_response.py) object.
These methods return an [`APIResponse`](https://github.com/mixedbread-ai/mixedbread-python/tree/main/src/mixedbread/_response.py) object.

The async client returns an [`AsyncAPIResponse`](https://github.com/stainless-sdks/mixedbread-python/tree/main/src/mixedbread/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
The async client returns an [`AsyncAPIResponse`](https://github.com/mixedbread-ai/mixedbread-python/tree/main/src/mixedbread/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.

#### `.with_streaming_response`

Expand All @@ -229,9 +286,7 @@ The above interface eagerly reads the full response body when you make the reque
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.

```python
with client.files.with_streaming_response.create(
file=b"raw file contents",
) as response:
with client.vector_stores.with_streaming_response.create() as response:
print(response.headers.get("X-My-Header"))

for line in response.iter_lines():
Expand Down Expand Up @@ -326,7 +381,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/mixedbread-python/issues) with questions, bugs, or suggestions.
We are keen for your feedback; please open an [issue](https://www.github.com/mixedbread-ai/mixedbread-python/issues) with questions, bugs, or suggestions.

### Determining the installed version

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or products provided by Mixedbread please follow the respective company's securi

### Mixedbread Terms and Policies

Please contact dev-feedback@mixedbread.com for any questions or concerns regarding security of our services.
Please contact support@mixedbread.ai for any questions or concerns regarding security of our services.

---

Expand Down
Loading