Skip to content

Commit

Permalink
chore(internal): codegen related update (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Dec 18, 2024
1 parent 694418c commit dcf8544
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 94 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ client.with_options(http_client=DefaultHttpxClient(...))

By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.

```py
from dataherald import Dataherald

with Dataherald() as client:
# make requests here
...

# HTTP client is now closed
```

## Versioning

This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
Expand Down
190 changes: 100 additions & 90 deletions src/dataherald/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import httpx

from . import resources, _exceptions
from . import _exceptions
from ._qs import Querystring
from ._types import (
NOT_GIVEN,
Expand All @@ -24,21 +24,25 @@
get_async_library,
)
from ._version import __version__
from .resources import engine, heartbeat, finetunings, generations, golden_sqls, nl_generations, table_descriptions
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._exceptions import APIStatusError, DataheraldError
from ._base_client import (
DEFAULT_MAX_RETRIES,
SyncAPIClient,
AsyncAPIClient,
)
from .resources.prompts import prompts
from .resources.instructions import instructions
from .resources.sql_generations import sql_generations
from .resources.database_connections import database_connections

__all__ = [
"ENVIRONMENTS",
"Timeout",
"Transport",
"ProxiesTypes",
"RequestOptions",
"resources",
"Dataherald",
"AsyncDataherald",
"Client",
Expand All @@ -52,17 +56,17 @@


class Dataherald(SyncAPIClient):
database_connections: resources.DatabaseConnectionsResource
finetunings: resources.FinetuningsResource
golden_sqls: resources.GoldenSqlsResource
instructions: resources.InstructionsResource
generations: resources.GenerationsResource
prompts: resources.PromptsResource
sql_generations: resources.SqlGenerationsResource
nl_generations: resources.NlGenerationsResource
table_descriptions: resources.TableDescriptionsResource
heartbeat: resources.HeartbeatResource
engine: resources.EngineResource
database_connections: database_connections.DatabaseConnectionsResource
finetunings: finetunings.FinetuningsResource
golden_sqls: golden_sqls.GoldenSqlsResource
instructions: instructions.InstructionsResource
generations: generations.GenerationsResource
prompts: prompts.PromptsResource
sql_generations: sql_generations.SqlGenerationsResource
nl_generations: nl_generations.NlGenerationsResource
table_descriptions: table_descriptions.TableDescriptionsResource
heartbeat: heartbeat.HeartbeatResource
engine: engine.EngineResource
with_raw_response: DataheraldWithRawResponse
with_streaming_response: DataheraldWithStreamedResponse

Expand Down Expand Up @@ -144,17 +148,17 @@ def __init__(
_strict_response_validation=_strict_response_validation,
)

self.database_connections = resources.DatabaseConnectionsResource(self)
self.finetunings = resources.FinetuningsResource(self)
self.golden_sqls = resources.GoldenSqlsResource(self)
self.instructions = resources.InstructionsResource(self)
self.generations = resources.GenerationsResource(self)
self.prompts = resources.PromptsResource(self)
self.sql_generations = resources.SqlGenerationsResource(self)
self.nl_generations = resources.NlGenerationsResource(self)
self.table_descriptions = resources.TableDescriptionsResource(self)
self.heartbeat = resources.HeartbeatResource(self)
self.engine = resources.EngineResource(self)
self.database_connections = database_connections.DatabaseConnectionsResource(self)
self.finetunings = finetunings.FinetuningsResource(self)
self.golden_sqls = golden_sqls.GoldenSqlsResource(self)
self.instructions = instructions.InstructionsResource(self)
self.generations = generations.GenerationsResource(self)
self.prompts = prompts.PromptsResource(self)
self.sql_generations = sql_generations.SqlGenerationsResource(self)
self.nl_generations = nl_generations.NlGenerationsResource(self)
self.table_descriptions = table_descriptions.TableDescriptionsResource(self)
self.heartbeat = heartbeat.HeartbeatResource(self)
self.engine = engine.EngineResource(self)
self.with_raw_response = DataheraldWithRawResponse(self)
self.with_streaming_response = DataheraldWithStreamedResponse(self)

Expand Down Expand Up @@ -266,17 +270,17 @@ def _make_status_error(


class AsyncDataherald(AsyncAPIClient):
database_connections: resources.AsyncDatabaseConnectionsResource
finetunings: resources.AsyncFinetuningsResource
golden_sqls: resources.AsyncGoldenSqlsResource
instructions: resources.AsyncInstructionsResource
generations: resources.AsyncGenerationsResource
prompts: resources.AsyncPromptsResource
sql_generations: resources.AsyncSqlGenerationsResource
nl_generations: resources.AsyncNlGenerationsResource
table_descriptions: resources.AsyncTableDescriptionsResource
heartbeat: resources.AsyncHeartbeatResource
engine: resources.AsyncEngineResource
database_connections: database_connections.AsyncDatabaseConnectionsResource
finetunings: finetunings.AsyncFinetuningsResource
golden_sqls: golden_sqls.AsyncGoldenSqlsResource
instructions: instructions.AsyncInstructionsResource
generations: generations.AsyncGenerationsResource
prompts: prompts.AsyncPromptsResource
sql_generations: sql_generations.AsyncSqlGenerationsResource
nl_generations: nl_generations.AsyncNlGenerationsResource
table_descriptions: table_descriptions.AsyncTableDescriptionsResource
heartbeat: heartbeat.AsyncHeartbeatResource
engine: engine.AsyncEngineResource
with_raw_response: AsyncDataheraldWithRawResponse
with_streaming_response: AsyncDataheraldWithStreamedResponse

Expand Down Expand Up @@ -358,17 +362,17 @@ def __init__(
_strict_response_validation=_strict_response_validation,
)

self.database_connections = resources.AsyncDatabaseConnectionsResource(self)
self.finetunings = resources.AsyncFinetuningsResource(self)
self.golden_sqls = resources.AsyncGoldenSqlsResource(self)
self.instructions = resources.AsyncInstructionsResource(self)
self.generations = resources.AsyncGenerationsResource(self)
self.prompts = resources.AsyncPromptsResource(self)
self.sql_generations = resources.AsyncSqlGenerationsResource(self)
self.nl_generations = resources.AsyncNlGenerationsResource(self)
self.table_descriptions = resources.AsyncTableDescriptionsResource(self)
self.heartbeat = resources.AsyncHeartbeatResource(self)
self.engine = resources.AsyncEngineResource(self)
self.database_connections = database_connections.AsyncDatabaseConnectionsResource(self)
self.finetunings = finetunings.AsyncFinetuningsResource(self)
self.golden_sqls = golden_sqls.AsyncGoldenSqlsResource(self)
self.instructions = instructions.AsyncInstructionsResource(self)
self.generations = generations.AsyncGenerationsResource(self)
self.prompts = prompts.AsyncPromptsResource(self)
self.sql_generations = sql_generations.AsyncSqlGenerationsResource(self)
self.nl_generations = nl_generations.AsyncNlGenerationsResource(self)
self.table_descriptions = table_descriptions.AsyncTableDescriptionsResource(self)
self.heartbeat = heartbeat.AsyncHeartbeatResource(self)
self.engine = engine.AsyncEngineResource(self)
self.with_raw_response = AsyncDataheraldWithRawResponse(self)
self.with_streaming_response = AsyncDataheraldWithStreamedResponse(self)

Expand Down Expand Up @@ -481,70 +485,76 @@ def _make_status_error(

class DataheraldWithRawResponse:
def __init__(self, client: Dataherald) -> None:
self.database_connections = resources.DatabaseConnectionsResourceWithRawResponse(client.database_connections)
self.finetunings = resources.FinetuningsResourceWithRawResponse(client.finetunings)
self.golden_sqls = resources.GoldenSqlsResourceWithRawResponse(client.golden_sqls)
self.instructions = resources.InstructionsResourceWithRawResponse(client.instructions)
self.generations = resources.GenerationsResourceWithRawResponse(client.generations)
self.prompts = resources.PromptsResourceWithRawResponse(client.prompts)
self.sql_generations = resources.SqlGenerationsResourceWithRawResponse(client.sql_generations)
self.nl_generations = resources.NlGenerationsResourceWithRawResponse(client.nl_generations)
self.table_descriptions = resources.TableDescriptionsResourceWithRawResponse(client.table_descriptions)
self.heartbeat = resources.HeartbeatResourceWithRawResponse(client.heartbeat)
self.engine = resources.EngineResourceWithRawResponse(client.engine)
self.database_connections = database_connections.DatabaseConnectionsResourceWithRawResponse(
client.database_connections
)
self.finetunings = finetunings.FinetuningsResourceWithRawResponse(client.finetunings)
self.golden_sqls = golden_sqls.GoldenSqlsResourceWithRawResponse(client.golden_sqls)
self.instructions = instructions.InstructionsResourceWithRawResponse(client.instructions)
self.generations = generations.GenerationsResourceWithRawResponse(client.generations)
self.prompts = prompts.PromptsResourceWithRawResponse(client.prompts)
self.sql_generations = sql_generations.SqlGenerationsResourceWithRawResponse(client.sql_generations)
self.nl_generations = nl_generations.NlGenerationsResourceWithRawResponse(client.nl_generations)
self.table_descriptions = table_descriptions.TableDescriptionsResourceWithRawResponse(client.table_descriptions)
self.heartbeat = heartbeat.HeartbeatResourceWithRawResponse(client.heartbeat)
self.engine = engine.EngineResourceWithRawResponse(client.engine)


class AsyncDataheraldWithRawResponse:
def __init__(self, client: AsyncDataherald) -> None:
self.database_connections = resources.AsyncDatabaseConnectionsResourceWithRawResponse(
self.database_connections = database_connections.AsyncDatabaseConnectionsResourceWithRawResponse(
client.database_connections
)
self.finetunings = resources.AsyncFinetuningsResourceWithRawResponse(client.finetunings)
self.golden_sqls = resources.AsyncGoldenSqlsResourceWithRawResponse(client.golden_sqls)
self.instructions = resources.AsyncInstructionsResourceWithRawResponse(client.instructions)
self.generations = resources.AsyncGenerationsResourceWithRawResponse(client.generations)
self.prompts = resources.AsyncPromptsResourceWithRawResponse(client.prompts)
self.sql_generations = resources.AsyncSqlGenerationsResourceWithRawResponse(client.sql_generations)
self.nl_generations = resources.AsyncNlGenerationsResourceWithRawResponse(client.nl_generations)
self.table_descriptions = resources.AsyncTableDescriptionsResourceWithRawResponse(client.table_descriptions)
self.heartbeat = resources.AsyncHeartbeatResourceWithRawResponse(client.heartbeat)
self.engine = resources.AsyncEngineResourceWithRawResponse(client.engine)
self.finetunings = finetunings.AsyncFinetuningsResourceWithRawResponse(client.finetunings)
self.golden_sqls = golden_sqls.AsyncGoldenSqlsResourceWithRawResponse(client.golden_sqls)
self.instructions = instructions.AsyncInstructionsResourceWithRawResponse(client.instructions)
self.generations = generations.AsyncGenerationsResourceWithRawResponse(client.generations)
self.prompts = prompts.AsyncPromptsResourceWithRawResponse(client.prompts)
self.sql_generations = sql_generations.AsyncSqlGenerationsResourceWithRawResponse(client.sql_generations)
self.nl_generations = nl_generations.AsyncNlGenerationsResourceWithRawResponse(client.nl_generations)
self.table_descriptions = table_descriptions.AsyncTableDescriptionsResourceWithRawResponse(
client.table_descriptions
)
self.heartbeat = heartbeat.AsyncHeartbeatResourceWithRawResponse(client.heartbeat)
self.engine = engine.AsyncEngineResourceWithRawResponse(client.engine)


class DataheraldWithStreamedResponse:
def __init__(self, client: Dataherald) -> None:
self.database_connections = resources.DatabaseConnectionsResourceWithStreamingResponse(
self.database_connections = database_connections.DatabaseConnectionsResourceWithStreamingResponse(
client.database_connections
)
self.finetunings = resources.FinetuningsResourceWithStreamingResponse(client.finetunings)
self.golden_sqls = resources.GoldenSqlsResourceWithStreamingResponse(client.golden_sqls)
self.instructions = resources.InstructionsResourceWithStreamingResponse(client.instructions)
self.generations = resources.GenerationsResourceWithStreamingResponse(client.generations)
self.prompts = resources.PromptsResourceWithStreamingResponse(client.prompts)
self.sql_generations = resources.SqlGenerationsResourceWithStreamingResponse(client.sql_generations)
self.nl_generations = resources.NlGenerationsResourceWithStreamingResponse(client.nl_generations)
self.table_descriptions = resources.TableDescriptionsResourceWithStreamingResponse(client.table_descriptions)
self.heartbeat = resources.HeartbeatResourceWithStreamingResponse(client.heartbeat)
self.engine = resources.EngineResourceWithStreamingResponse(client.engine)
self.finetunings = finetunings.FinetuningsResourceWithStreamingResponse(client.finetunings)
self.golden_sqls = golden_sqls.GoldenSqlsResourceWithStreamingResponse(client.golden_sqls)
self.instructions = instructions.InstructionsResourceWithStreamingResponse(client.instructions)
self.generations = generations.GenerationsResourceWithStreamingResponse(client.generations)
self.prompts = prompts.PromptsResourceWithStreamingResponse(client.prompts)
self.sql_generations = sql_generations.SqlGenerationsResourceWithStreamingResponse(client.sql_generations)
self.nl_generations = nl_generations.NlGenerationsResourceWithStreamingResponse(client.nl_generations)
self.table_descriptions = table_descriptions.TableDescriptionsResourceWithStreamingResponse(
client.table_descriptions
)
self.heartbeat = heartbeat.HeartbeatResourceWithStreamingResponse(client.heartbeat)
self.engine = engine.EngineResourceWithStreamingResponse(client.engine)


class AsyncDataheraldWithStreamedResponse:
def __init__(self, client: AsyncDataherald) -> None:
self.database_connections = resources.AsyncDatabaseConnectionsResourceWithStreamingResponse(
self.database_connections = database_connections.AsyncDatabaseConnectionsResourceWithStreamingResponse(
client.database_connections
)
self.finetunings = resources.AsyncFinetuningsResourceWithStreamingResponse(client.finetunings)
self.golden_sqls = resources.AsyncGoldenSqlsResourceWithStreamingResponse(client.golden_sqls)
self.instructions = resources.AsyncInstructionsResourceWithStreamingResponse(client.instructions)
self.generations = resources.AsyncGenerationsResourceWithStreamingResponse(client.generations)
self.prompts = resources.AsyncPromptsResourceWithStreamingResponse(client.prompts)
self.sql_generations = resources.AsyncSqlGenerationsResourceWithStreamingResponse(client.sql_generations)
self.nl_generations = resources.AsyncNlGenerationsResourceWithStreamingResponse(client.nl_generations)
self.table_descriptions = resources.AsyncTableDescriptionsResourceWithStreamingResponse(
self.finetunings = finetunings.AsyncFinetuningsResourceWithStreamingResponse(client.finetunings)
self.golden_sqls = golden_sqls.AsyncGoldenSqlsResourceWithStreamingResponse(client.golden_sqls)
self.instructions = instructions.AsyncInstructionsResourceWithStreamingResponse(client.instructions)
self.generations = generations.AsyncGenerationsResourceWithStreamingResponse(client.generations)
self.prompts = prompts.AsyncPromptsResourceWithStreamingResponse(client.prompts)
self.sql_generations = sql_generations.AsyncSqlGenerationsResourceWithStreamingResponse(client.sql_generations)
self.nl_generations = nl_generations.AsyncNlGenerationsResourceWithStreamingResponse(client.nl_generations)
self.table_descriptions = table_descriptions.AsyncTableDescriptionsResourceWithStreamingResponse(
client.table_descriptions
)
self.heartbeat = resources.AsyncHeartbeatResourceWithStreamingResponse(client.heartbeat)
self.engine = resources.AsyncEngineResourceWithStreamingResponse(client.engine)
self.heartbeat = heartbeat.AsyncHeartbeatResourceWithStreamingResponse(client.heartbeat)
self.engine = engine.AsyncEngineResourceWithStreamingResponse(client.engine)


Client = Dataherald
Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ def test_default_query_option(self) -> None:
FinalRequestOptions(
method="get",
url="/foo",
params={"foo": "baz", "query_param": "overriden"},
params={"foo": "baz", "query_param": "overridden"},
)
)
url = httpx.URL(request.url)
assert dict(url.params) == {"foo": "baz", "query_param": "overriden"}
assert dict(url.params) == {"foo": "baz", "query_param": "overridden"}

def test_request_extra_json(self) -> None:
request = self.client._build_request(
Expand Down Expand Up @@ -1119,11 +1119,11 @@ def test_default_query_option(self) -> None:
FinalRequestOptions(
method="get",
url="/foo",
params={"foo": "baz", "query_param": "overriden"},
params={"foo": "baz", "query_param": "overridden"},
)
)
url = httpx.URL(request.url)
assert dict(url.params) == {"foo": "baz", "query_param": "overriden"}
assert dict(url.params) == {"foo": "baz", "query_param": "overridden"}

def test_request_extra_json(self) -> None:
request = self.client._build_request(
Expand Down

0 comments on commit dcf8544

Please sign in to comment.