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/BrainbaseHQ/brainbase-python-sdk/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.BRAINBASE_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 == 'BrainbaseHQ/brainbase-python-sdk' && (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.BRAINBASE_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.0.1-alpha.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 14
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-6f838e7577a70ce7ba003119a6923a3cc26aaf0deede2045104dfcf4beebf664.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/brainbase-egrigokhan%2Fbrainbase-0c00485d66a3b7505f3247467ef293fa5fb43a64e90a8b03a4127a2d9b15e6ab.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://[email protected]/stainless-sdks/brainbase-python.git
$ pip install git+ssh://[email protected]/BrainbaseHQ/brainbase-python-sdk.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/brainbase-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/BrainbaseHQ/brainbase-python-sdk/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

Expand Down
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Brainbase Python API library

[![PyPI version](https://img.shields.io/pypi/v/brainbase.svg)](https://pypi.org/project/brainbase/)
[![PyPI version](https://img.shields.io/pypi/v/brainbase-labs.svg)](https://pypi.org/project/brainbase-labs/)

The Brainbase Python library provides convenient access to the Brainbase REST API from any Python 3.8+
application. The library includes type definitions for all request params and response fields,
Expand All @@ -15,37 +15,41 @@ The REST API documentation can be found on [docs.brainbase.com](https://docs.bra
## Installation

```sh
# install from this staging repo
pip install git+ssh://[email protected]/stainless-sdks/brainbase-python.git
# install from PyPI
pip install --pre brainbase-labs
```

> [!NOTE]
> Once this package is [published to PyPI](https://app.stainlessapi.com/docs/guides/publish), this will become: `pip install --pre brainbase`

## Usage

The full API of this library can be found in [api.md](api.md).

```python
import os
from brainbase import Brainbase

client = Brainbase(
api_key="My API Key",
api_key=os.environ.get("BRAINBASE_API_KEY"), # This is the default and can be omitted
)

client.workers.list()
```

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

## Async usage

Simply import `AsyncBrainbase` instead of `Brainbase` and use `await` with each API call:

```python
import os
import asyncio
from brainbase import AsyncBrainbase

client = AsyncBrainbase(
api_key="My API Key",
api_key=os.environ.get("BRAINBASE_API_KEY"), # This is the default and can be omitted
)


Expand Down Expand Up @@ -80,9 +84,7 @@ All errors inherit from `brainbase.APIError`.
import brainbase
from brainbase import Brainbase

client = Brainbase(
api_key="My API Key",
)
client = Brainbase()

try:
client.workers.list()
Expand Down Expand Up @@ -125,7 +127,6 @@ from brainbase import Brainbase
client = Brainbase(
# default is 2
max_retries=0,
api_key="My API Key",
)

# Or, configure per-request:
Expand All @@ -144,13 +145,11 @@ from brainbase import Brainbase
client = Brainbase(
# 20 seconds (default is 1 minute)
timeout=20.0,
api_key="My API Key",
)

# More granular control:
client = Brainbase(
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
api_key="My API Key",
)

# Override per-request:
Expand Down Expand Up @@ -194,19 +193,17 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
```py
from brainbase import Brainbase

client = Brainbase(
api_key="My API Key",
)
client = Brainbase()
response = client.workers.with_raw_response.list()
print(response.headers.get('X-My-Header'))

worker = response.parse() # get the object that `workers.list()` would have returned
print(worker)
```

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

The async client returns an [`AsyncAPIResponse`](https://github.com/stainless-sdks/brainbase-python/tree/main/src/brainbase/_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/BrainbaseHQ/brainbase-python-sdk/tree/main/src/brainbase/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.

#### `.with_streaming_response`

Expand Down Expand Up @@ -277,7 +274,6 @@ client = Brainbase(
proxy="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
api_key="My API Key",
)
```

Expand All @@ -294,9 +290,7 @@ By default the library closes underlying HTTP connections whenever the client is
```py
from brainbase import Brainbase

with Brainbase(
api_key="My API Key",
) as client:
with Brainbase() as client:
# make requests here
...

Expand All @@ -313,7 +307,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/brainbase-python/issues) with questions, bugs, or suggestions.
We are keen for your feedback; please open an [issue](https://www.github.com/BrainbaseHQ/brainbase-python-sdk/issues) with questions, bugs, or suggestions.

### Determining the installed version

Expand Down
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Methods:

- <code title="post /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">create</a>(id, \*\*<a href="src/brainbase/types/worker_create_params.py">params</a>) -> None</code>
- <code title="post /api/workers">client.workers.<a href="./src/brainbase/resources/workers/workers.py">create</a>(\*\*<a href="src/brainbase/types/worker_create_params.py">params</a>) -> None</code>
- <code title="get /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">retrieve</a>(id) -> None</code>
- <code title="get /api/workers">client.workers.<a href="./src/brainbase/resources/workers/workers.py">list</a>() -> None</code>
- <code title="delete /api/workers/{id}">client.workers.<a href="./src/brainbase/resources/workers/workers.py">delete</a>(id) -> None</code>
Expand Down
21 changes: 21 additions & 0 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

errors=()

if [ -z "${PYPI_TOKEN}" ]; then
errors+=("The BRAINBASE_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
fi

lenErrors=${#errors[@]}

if [[ lenErrors -gt 0 ]]; then
echo -e "Found the following errors in the release environment:\n"

for error in "${errors[@]}"; do
echo -e "- $error\n"
done

exit 1
fi

echo "The environment is ready to push releases!"
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "brainbase"
name = "brainbase-labs"
version = "0.0.1-alpha.0"
description = "The official Python library for the brainbase API"
dynamic = ["readme"]
Expand Down Expand Up @@ -34,8 +34,8 @@ classifiers = [
]

[project.urls]
Homepage = "https://github.com/stainless-sdks/brainbase-python"
Repository = "https://github.com/stainless-sdks/brainbase-python"
Homepage = "https://github.com/BrainbaseHQ/brainbase-python-sdk"
Repository = "https://github.com/BrainbaseHQ/brainbase-python-sdk"



Expand Down Expand Up @@ -122,7 +122,7 @@ path = "README.md"
[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
# replace relative links with absolute links
pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
replacement = '[\1](https://github.com/stainless-sdks/brainbase-python/tree/main/\g<2>)'
replacement = '[\1](https://github.com/BrainbaseHQ/brainbase-python-sdk/tree/main/\g<2>)'

[tool.pytest.ini_options]
testpaths = ["tests"]
Expand Down
66 changes: 66 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"packages": {
".": {}
},
"$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json",
"include-v-in-tag": true,
"include-component-in-tag": false,
"versioning": "prerelease",
"prerelease": true,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": false,
"pull-request-header": "Automated Release PR",
"pull-request-title-pattern": "release: ${version}",
"changelog-sections": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "chore",
"section": "Chores"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "style",
"section": "Styles"
},
{
"type": "refactor",
"section": "Refactors"
},
{
"type": "test",
"section": "Tests",
"hidden": true
},
{
"type": "build",
"section": "Build System"
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": true
}
],
"release-type": "python",
"extra-files": [
"src/brainbase/_version.py"
]
}
Loading