diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml new file mode 100644 index 00000000..3fbc99f8 --- /dev/null +++ b/.github/workflows/publish-pypi.yml @@ -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 }} diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml new file mode 100644 index 00000000..7c642abf --- /dev/null +++ b/.github/workflows/release-doctor.yml @@ -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 }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 00000000..c4762802 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.1-alpha.0" +} \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index e09e1277..73df72e5 100644 --- a/.stats.yml +++ b/.stats.yml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 59ea9089..2cf8f44a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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/brainbase-python.git +$ pip install git+ssh://git@github.com/BrainbaseHQ/brainbase-python-sdk.git ``` Alternatively, you can build from source and install the wheel file: @@ -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 diff --git a/README.md b/README.md index 6787b111..bd87518a 100644 --- a/README.md +++ b/README.md @@ -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, @@ -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://git@github.com/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 ) @@ -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() @@ -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: @@ -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: @@ -194,9 +193,7 @@ 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')) @@ -204,9 +201,9 @@ worker = response.parse() # get the object that `workers.list()` would have ret 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` @@ -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", ) ``` @@ -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 ... @@ -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 diff --git a/api.md b/api.md index 77b07ee9..6f634335 100644 --- a/api.md +++ b/api.md @@ -2,7 +2,7 @@ Methods: -- client.workers.create(id, \*\*params) -> None +- client.workers.create(\*\*params) -> None - client.workers.retrieve(id) -> None - client.workers.list() -> None - client.workers.delete(id) -> None diff --git a/bin/check-release-environment b/bin/check-release-environment new file mode 100644 index 00000000..59422a48 --- /dev/null +++ b/bin/check-release-environment @@ -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!" diff --git a/pyproject.toml b/pyproject.toml index d8ace7b9..52a90e3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] @@ -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" @@ -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"] diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 00000000..3f255933 --- /dev/null +++ b/release-please-config.json @@ -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" + ] +} \ No newline at end of file diff --git a/requirements-dev.lock b/requirements-dev.lock index 8ab32139..2ccbd89c 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -12,7 +12,7 @@ annotated-types==0.6.0 # via pydantic anyio==4.4.0 - # via brainbase + # via brainbase-labs # via httpx argcomplete==3.1.2 # via nox @@ -25,7 +25,7 @@ dirty-equals==0.6.0 distlib==0.3.7 # via virtualenv distro==1.8.0 - # via brainbase + # via brainbase-labs exceptiongroup==1.2.2 # via anyio # via pytest @@ -36,7 +36,7 @@ h11==0.14.0 httpcore==1.0.2 # via httpx httpx==0.28.1 - # via brainbase + # via brainbase-labs # via respx idna==3.4 # via anyio @@ -63,7 +63,7 @@ platformdirs==3.11.0 pluggy==1.5.0 # via pytest pydantic==2.10.3 - # via brainbase + # via brainbase-labs pydantic-core==2.27.1 # via pydantic pygments==2.18.0 @@ -85,14 +85,14 @@ six==1.16.0 # via python-dateutil sniffio==1.3.0 # via anyio - # via brainbase + # via brainbase-labs time-machine==2.9.0 tomli==2.0.2 # via mypy # via pytest typing-extensions==4.12.2 # via anyio - # via brainbase + # via brainbase-labs # via mypy # via pydantic # via pydantic-core diff --git a/requirements.lock b/requirements.lock index c06830b2..ab585024 100644 --- a/requirements.lock +++ b/requirements.lock @@ -12,13 +12,13 @@ annotated-types==0.6.0 # via pydantic anyio==4.4.0 - # via brainbase + # via brainbase-labs # via httpx certifi==2023.7.22 # via httpcore # via httpx distro==1.8.0 - # via brainbase + # via brainbase-labs exceptiongroup==1.2.2 # via anyio h11==0.14.0 @@ -26,19 +26,19 @@ h11==0.14.0 httpcore==1.0.2 # via httpx httpx==0.28.1 - # via brainbase + # via brainbase-labs idna==3.4 # via anyio # via httpx pydantic==2.10.3 - # via brainbase + # via brainbase-labs pydantic-core==2.27.1 # via pydantic sniffio==1.3.0 # via anyio - # via brainbase + # via brainbase-labs typing-extensions==4.12.2 # via anyio - # via brainbase + # via brainbase-labs # via pydantic # via pydantic-core diff --git a/src/brainbase/_client.py b/src/brainbase/_client.py index bbe9a56d..9192a946 100644 --- a/src/brainbase/_client.py +++ b/src/brainbase/_client.py @@ -113,6 +113,12 @@ def __init__( def qs(self) -> Querystring: return Querystring(array_format="comma") + @property + @override + def auth_headers(self) -> dict[str, str]: + api_key = self.api_key + return {"x-api-key": api_key} + @property @override def default_headers(self) -> dict[str, str | Omit]: @@ -275,6 +281,12 @@ def __init__( def qs(self) -> Querystring: return Querystring(array_format="comma") + @property + @override + def auth_headers(self) -> dict[str, str]: + api_key = self.api_key + return {"x-api-key": api_key} + @property @override def default_headers(self) -> dict[str, str | Omit]: diff --git a/src/brainbase/_version.py b/src/brainbase/_version.py index f41cdb5a..29916c66 100644 --- a/src/brainbase/_version.py +++ b/src/brainbase/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "brainbase" -__version__ = "0.0.1-alpha.0" +__version__ = "0.0.1-alpha.0" # x-release-please-version diff --git a/src/brainbase/resources/workers/deployments/deployments.py b/src/brainbase/resources/workers/deployments/deployments.py index 13a0ae86..93735470 100644 --- a/src/brainbase/resources/workers/deployments/deployments.py +++ b/src/brainbase/resources/workers/deployments/deployments.py @@ -27,7 +27,7 @@ def with_raw_response(self) -> DeploymentsResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return DeploymentsResourceWithRawResponse(self) @@ -36,7 +36,7 @@ def with_streaming_response(self) -> DeploymentsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return DeploymentsResourceWithStreamingResponse(self) @@ -52,7 +52,7 @@ def with_raw_response(self) -> AsyncDeploymentsResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return AsyncDeploymentsResourceWithRawResponse(self) @@ -61,7 +61,7 @@ def with_streaming_response(self) -> AsyncDeploymentsResourceWithStreamingRespon """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return AsyncDeploymentsResourceWithStreamingResponse(self) diff --git a/src/brainbase/resources/workers/deployments/voice.py b/src/brainbase/resources/workers/deployments/voice.py index b82a3386..57cc1313 100644 --- a/src/brainbase/resources/workers/deployments/voice.py +++ b/src/brainbase/resources/workers/deployments/voice.py @@ -30,7 +30,7 @@ def with_raw_response(self) -> VoiceResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return VoiceResourceWithRawResponse(self) @@ -39,7 +39,7 @@ def with_streaming_response(self) -> VoiceResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return VoiceResourceWithStreamingResponse(self) @@ -264,7 +264,7 @@ def with_raw_response(self) -> AsyncVoiceResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return AsyncVoiceResourceWithRawResponse(self) @@ -273,7 +273,7 @@ def with_streaming_response(self) -> AsyncVoiceResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return AsyncVoiceResourceWithStreamingResponse(self) diff --git a/src/brainbase/resources/workers/flows.py b/src/brainbase/resources/workers/flows.py index 2b27f22d..f91b1a3b 100644 --- a/src/brainbase/resources/workers/flows.py +++ b/src/brainbase/resources/workers/flows.py @@ -30,7 +30,7 @@ def with_raw_response(self) -> FlowsResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return FlowsResourceWithRawResponse(self) @@ -39,7 +39,7 @@ def with_streaming_response(self) -> FlowsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return FlowsResourceWithStreamingResponse(self) @@ -252,7 +252,7 @@ def with_raw_response(self) -> AsyncFlowsResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return AsyncFlowsResourceWithRawResponse(self) @@ -261,7 +261,7 @@ def with_streaming_response(self) -> AsyncFlowsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return AsyncFlowsResourceWithStreamingResponse(self) diff --git a/src/brainbase/resources/workers/workers.py b/src/brainbase/resources/workers/workers.py index ced9ec05..9d2eb83c 100644 --- a/src/brainbase/resources/workers/workers.py +++ b/src/brainbase/resources/workers/workers.py @@ -54,7 +54,7 @@ def with_raw_response(self) -> WorkersResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return WorkersResourceWithRawResponse(self) @@ -63,16 +63,15 @@ def with_streaming_response(self) -> WorkersResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return WorkersResourceWithStreamingResponse(self) def create( self, - id: str, *, + name: str, description: str | NotGiven = NOT_GIVEN, - name: str | NotGiven = NOT_GIVEN, status: str | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -82,7 +81,7 @@ def create( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> None: """ - Update a worker + Create a new worker Args: extra_headers: Send extra headers @@ -93,15 +92,13 @@ def create( timeout: Override the client-level default timeout for this request, in seconds """ - if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._post( - f"/api/workers/{id}", + "/api/workers", body=maybe_transform( { - "description": description, "name": name, + "description": description, "status": status, }, worker_create_params.WorkerCreateParams, @@ -216,7 +213,7 @@ def with_raw_response(self) -> AsyncWorkersResourceWithRawResponse: This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#accessing-raw-response-data-eg-headers + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#accessing-raw-response-data-eg-headers """ return AsyncWorkersResourceWithRawResponse(self) @@ -225,16 +222,15 @@ def with_streaming_response(self) -> AsyncWorkersResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/brainbase-python#with_streaming_response + For more information, see https://www.github.com/BrainbaseHQ/brainbase-python-sdk#with_streaming_response """ return AsyncWorkersResourceWithStreamingResponse(self) async def create( self, - id: str, *, + name: str, description: str | NotGiven = NOT_GIVEN, - name: str | NotGiven = NOT_GIVEN, status: str | NotGiven = NOT_GIVEN, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. @@ -244,7 +240,7 @@ async def create( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> None: """ - Update a worker + Create a new worker Args: extra_headers: Send extra headers @@ -255,15 +251,13 @@ async def create( timeout: Override the client-level default timeout for this request, in seconds """ - if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._post( - f"/api/workers/{id}", + "/api/workers", body=await async_maybe_transform( { - "description": description, "name": name, + "description": description, "status": status, }, worker_create_params.WorkerCreateParams, diff --git a/src/brainbase/types/worker_create_params.py b/src/brainbase/types/worker_create_params.py index f84e516c..757c0420 100644 --- a/src/brainbase/types/worker_create_params.py +++ b/src/brainbase/types/worker_create_params.py @@ -2,14 +2,14 @@ from __future__ import annotations -from typing_extensions import TypedDict +from typing_extensions import Required, TypedDict __all__ = ["WorkerCreateParams"] class WorkerCreateParams(TypedDict, total=False): - description: str + name: Required[str] - name: str + description: str status: str diff --git a/tests/api_resources/test_workers.py b/tests/api_resources/test_workers.py index a6c4d926..5f524f47 100644 --- a/tests/api_resources/test_workers.py +++ b/tests/api_resources/test_workers.py @@ -19,7 +19,7 @@ class TestWorkers: @parametrize def test_method_create(self, client: Brainbase) -> None: worker = client.workers.create( - id="id", + name="name", ) assert worker is None @@ -27,9 +27,8 @@ def test_method_create(self, client: Brainbase) -> None: @parametrize def test_method_create_with_all_params(self, client: Brainbase) -> None: worker = client.workers.create( - id="id", - description="description", name="name", + description="description", status="status", ) assert worker is None @@ -38,7 +37,7 @@ def test_method_create_with_all_params(self, client: Brainbase) -> None: @parametrize def test_raw_response_create(self, client: Brainbase) -> None: response = client.workers.with_raw_response.create( - id="id", + name="name", ) assert response.is_closed is True @@ -50,7 +49,7 @@ def test_raw_response_create(self, client: Brainbase) -> None: @parametrize def test_streaming_response_create(self, client: Brainbase) -> None: with client.workers.with_streaming_response.create( - id="id", + name="name", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -60,14 +59,6 @@ def test_streaming_response_create(self, client: Brainbase) -> None: assert cast(Any, response.is_closed) is True - @pytest.mark.skip() - @parametrize - def test_path_params_create(self, client: Brainbase) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.workers.with_raw_response.create( - id="", - ) - @pytest.mark.skip() @parametrize def test_method_retrieve(self, client: Brainbase) -> None: @@ -188,7 +179,7 @@ class TestAsyncWorkers: @parametrize async def test_method_create(self, async_client: AsyncBrainbase) -> None: worker = await async_client.workers.create( - id="id", + name="name", ) assert worker is None @@ -196,9 +187,8 @@ async def test_method_create(self, async_client: AsyncBrainbase) -> None: @parametrize async def test_method_create_with_all_params(self, async_client: AsyncBrainbase) -> None: worker = await async_client.workers.create( - id="id", - description="description", name="name", + description="description", status="status", ) assert worker is None @@ -207,7 +197,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncBrainbase) @parametrize async def test_raw_response_create(self, async_client: AsyncBrainbase) -> None: response = await async_client.workers.with_raw_response.create( - id="id", + name="name", ) assert response.is_closed is True @@ -219,7 +209,7 @@ async def test_raw_response_create(self, async_client: AsyncBrainbase) -> None: @parametrize async def test_streaming_response_create(self, async_client: AsyncBrainbase) -> None: async with async_client.workers.with_streaming_response.create( - id="id", + name="name", ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -229,14 +219,6 @@ async def test_streaming_response_create(self, async_client: AsyncBrainbase) -> assert cast(Any, response.is_closed) is True - @pytest.mark.skip() - @parametrize - async def test_path_params_create(self, async_client: AsyncBrainbase) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.workers.with_raw_response.create( - id="", - ) - @pytest.mark.skip() @parametrize async def test_method_retrieve(self, async_client: AsyncBrainbase) -> None: diff --git a/tests/test_client.py b/tests/test_client.py index c4074ec6..4bf71630 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -25,7 +25,7 @@ from brainbase._types import Omit from brainbase._models import BaseModel, FinalRequestOptions from brainbase._constants import RAW_RESPONSE_HEADER -from brainbase._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError +from brainbase._exceptions import APIStatusError, BrainbaseError, APITimeoutError, APIResponseValidationError from brainbase._base_client import ( DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, @@ -334,6 +334,16 @@ def test_default_headers_option(self) -> None: assert request.headers.get("x-foo") == "stainless" assert request.headers.get("x-stainless-lang") == "my-overriding-header" + def test_validate_headers(self) -> None: + client = Brainbase(base_url=base_url, api_key=api_key, _strict_response_validation=True) + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + assert request.headers.get("x-api-key") == api_key + + with pytest.raises(BrainbaseError): + with update_env(**{"BRAINBASE_API_KEY": Omit()}): + client2 = Brainbase(base_url=base_url, api_key=None, _strict_response_validation=True) + _ = client2 + def test_default_query_option(self) -> None: client = Brainbase( base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} @@ -1080,6 +1090,16 @@ def test_default_headers_option(self) -> None: assert request.headers.get("x-foo") == "stainless" assert request.headers.get("x-stainless-lang") == "my-overriding-header" + def test_validate_headers(self) -> None: + client = AsyncBrainbase(base_url=base_url, api_key=api_key, _strict_response_validation=True) + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + assert request.headers.get("x-api-key") == api_key + + with pytest.raises(BrainbaseError): + with update_env(**{"BRAINBASE_API_KEY": Omit()}): + client2 = AsyncBrainbase(base_url=base_url, api_key=None, _strict_response_validation=True) + _ = client2 + def test_default_query_option(self) -> None: client = AsyncBrainbase( base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"}