-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated Release PR --- ## 0.1.0-beta.0 (2024-08-22) Full Changelog: [v0.1.0-alpha.4...v0.1.0-beta.0](v0.1.0-alpha.4...v0.1.0-beta.0) ### Features * **api:** OpenAPI spec update via Stainless API ([#46](#46)) ([40b3e77](40b3e77)) * **api:** OpenAPI spec update via Stainless API ([#47](#47)) ([dc0a486](dc0a486)) * **api:** OpenAPI spec update via Stainless API ([#51](#51)) ([32b51b7](32b51b7)) * **api:** OpenAPI spec update via Stainless API ([#52](#52)) ([19e0b68](19e0b68)) * **api:** OpenAPI spec update via Stainless API ([#54](#54)) ([f82e637](f82e637)) * **api:** OpenAPI spec update via Stainless API ([#57](#57)) ([768bb4c](768bb4c)) * **api:** OpenAPI spec update via Stainless API ([#59](#59)) ([99508ad](99508ad)) * **api:** OpenAPI spec update via Stainless API ([#60](#60)) ([1bdc085](1bdc085)) * **api:** OpenAPI spec update via Stainless API ([#61](#61)) ([8a58b5c](8a58b5c)) * **api:** OpenAPI spec update via Stainless API ([#62](#62)) ([6fd1a9f](6fd1a9f)) * **api:** OpenAPI spec update via Stainless API ([#63](#63)) ([289a809](289a809)) * **api:** OpenAPI spec update via Stainless API ([#70](#70)) ([b4ff212](b4ff212)) * **api:** OpenAPI spec update via Stainless API ([#71](#71)) ([8ed8ccb](8ed8ccb)) * **api:** OpenAPI spec update via Stainless API ([#72](#72)) ([b5e6b00](b5e6b00)) * **api:** OpenAPI spec update via Stainless API ([#73](#73)) ([92000b7](92000b7)) * **client:** add `retry_count` to raw response class ([#44](#44)) ([aa7658d](aa7658d)) ### Bug Fixes * **client:** correctly serialise array body params ([#50](#50)) ([88156f9](88156f9)) ### Chores * **ci:** also run pydantic v1 tests ([#69](#69)) ([84f5669](84f5669)) * **ci:** bump prism mock server version ([#55](#55)) ([1bd186d](1bd186d)) * **client:** fix parsing union responses when non-json is returned ([#66](#66)) ([51d2a84](51d2a84)) * **examples:** minor formatting changes ([#58](#58)) ([a518d00](a518d00)) * **internal:** bump pyright ([#43](#43)) ([19e30f3](19e30f3)) * **internal:** bump ruff version ([#48](#48)) ([b91ea15](b91ea15)) * **internal:** ensure package is importable in lint cmd ([#56](#56)) ([1a99c7e](1a99c7e)) * **internal:** remove deprecated ruff config ([#53](#53)) ([36a843f](36a843f)) * **internal:** test updates ([#45](#45)) ([d0c9e05](d0c9e05)) * **internal:** update pydantic compat helper function ([#49](#49)) ([c057767](c057767)) * **internal:** use `TypeAlias` marker for type assignments ([#41](#41)) ([46f909b](46f909b)) * **internal:** use different 32bit detection method ([#64](#64)) ([bec41c2](bec41c2)) * update SDK settings ([#65](#65)) ([4ac3a29](4ac3a29)) --- This pull request is managed by Stainless's [GitHub App](https://github.com/apps/stainless-app). The [semver version number](https://semver.org/#semantic-versioning-specification-semver) is based on included [commit messages](https://www.conventionalcommits.org/en/v1.0.0/). Alternatively, you can manually set the version number in the title of this pull request. For a better experience, it is recommended to use either rebase-merge or squash-merge when merging this pull request. 🔗 Stainless [website](https://www.stainlessapi.com) 📚 Read the [docs](https://app.stainlessapi.com/docs) 🙋 [Reach out](mailto:[email protected]) for help or questions --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com> Co-authored-by: Jay Kim <[email protected]>
- Loading branch information
1 parent
c847795
commit 23089c9
Showing
320 changed files
with
19,715 additions
and
918 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
".": "0.1.0-alpha.4" | ||
".": "0.1.0-beta.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
configured_endpoints: 48 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome%2Fmetronome-115e754ed55ead15816eea022ce7352fbdd0bd0cff851d13ec173f4557e45ec2.yml | ||
configured_endpoints: 87 | ||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/metronome%2Fmetronome-085bb8699d222fd7950750078c4ea00fb8728477809a8ebc74521a7ad5f32038.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,10 @@ client = Metronome( | |
response = client.usage.ingest( | ||
usage=[ | ||
{ | ||
"transaction_id": "2021-01-01T00:00:00Z_cluster42", | ||
"customer_id": "[email protected]", | ||
"event_type": "heartbeat", | ||
"timestamp": "2021-01-01T00:00:00Z", | ||
"transaction_id": "2021-01-01T00:00:00Z_cluster42", | ||
} | ||
], | ||
) | ||
|
@@ -70,10 +70,10 @@ async def main() -> None: | |
response = await client.usage.ingest( | ||
usage=[ | ||
{ | ||
"transaction_id": "2021-01-01T00:00:00Z_cluster42", | ||
"customer_id": "[email protected]", | ||
"event_type": "heartbeat", | ||
"timestamp": "2021-01-01T00:00:00Z", | ||
"transaction_id": "2021-01-01T00:00:00Z_cluster42", | ||
} | ||
], | ||
) | ||
|
@@ -93,6 +93,69 @@ 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 Metronome 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 metronome import Metronome | ||
|
||
client = Metronome() | ||
|
||
all_products = [] | ||
# Automatically fetches more pages as needed. | ||
for product in client.contracts.products.list(): | ||
# Do something with product here | ||
all_products.append(product) | ||
print(all_products) | ||
``` | ||
|
||
Or, asynchronously: | ||
|
||
```python | ||
import asyncio | ||
from metronome import AsyncMetronome | ||
|
||
client = AsyncMetronome() | ||
|
||
|
||
async def main() -> None: | ||
all_products = [] | ||
# Iterate through items across all pages, issuing requests as needed. | ||
async for product in client.contracts.products.list(): | ||
all_products.append(product) | ||
print(all_products) | ||
|
||
|
||
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.contracts.products.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.contracts.products.list() | ||
|
||
print(f"next page cursor: {first_page.next_page}") # => "next page cursor: ..." | ||
for product in first_page.data: | ||
print(product.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 `metronome.APIConnectionError` is raised. | ||
|
@@ -103,16 +166,17 @@ response), a subclass of `metronome.APIStatusError` is raised, containing `statu | |
All errors inherit from `metronome.APIError`. | ||
|
||
```python | ||
from metronome._utils import parse_datetime | ||
|
||
import metronome | ||
from metronome import Metronome | ||
|
||
client = Metronome() | ||
|
||
try: | ||
client.alerts.create( | ||
alert_type="spend_threshold_reached", | ||
name="$100 spend threshold reached", | ||
threshold=10000, | ||
client.contracts.create( | ||
customer_id="13117714-3f05-48e5-a6e9-a66093f13b4d", | ||
starting_at=parse_datetime("2020-01-01T00:00:00.000Z"), | ||
) | ||
except metronome.APIConnectionError as e: | ||
print("The server could not be reached") | ||
|
@@ -147,6 +211,8 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ | |
You can use the `max_retries` option to configure or disable retry settings: | ||
|
||
```python | ||
from metronome._utils import parse_datetime | ||
|
||
from metronome import Metronome | ||
|
||
# Configure the default for all requests: | ||
|
@@ -156,10 +222,9 @@ client = Metronome( | |
) | ||
|
||
# Or, configure per-request: | ||
client.with_options(max_retries=5).alerts.create( | ||
alert_type="spend_threshold_reached", | ||
name="$100 spend threshold reached", | ||
threshold=10000, | ||
client.with_options(max_retries=5).contracts.create( | ||
customer_id="13117714-3f05-48e5-a6e9-a66093f13b4d", | ||
starting_at=parse_datetime("2020-01-01T00:00:00.000Z"), | ||
) | ||
``` | ||
|
||
|
@@ -169,6 +234,8 @@ By default requests time out after 1 minute. You can configure this with a `time | |
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object: | ||
|
||
```python | ||
from metronome._utils import parse_datetime | ||
|
||
from metronome import Metronome | ||
|
||
# Configure the default for all requests: | ||
|
@@ -183,10 +250,9 @@ client = Metronome( | |
) | ||
|
||
# Override per-request: | ||
client.with_options(timeout=5.0).alerts.create( | ||
alert_type="spend_threshold_reached", | ||
name="$100 spend threshold reached", | ||
threshold=10000, | ||
client.with_options(timeout=5.0).contracts.create( | ||
customer_id="13117714-3f05-48e5-a6e9-a66093f13b4d", | ||
starting_at=parse_datetime("2020-01-01T00:00:00.000Z"), | ||
) | ||
``` | ||
|
||
|
@@ -226,15 +292,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to | |
from metronome import Metronome | ||
|
||
client = Metronome() | ||
response = client.alerts.with_raw_response.create( | ||
alert_type="spend_threshold_reached", | ||
name="$100 spend threshold reached", | ||
threshold=10000, | ||
response = client.contracts.with_raw_response.create( | ||
customer_id="13117714-3f05-48e5-a6e9-a66093f13b4d", | ||
starting_at=parse_datetime("2020-01-01T00:00:00.000Z"), | ||
) | ||
print(response.headers.get('X-My-Header')) | ||
|
||
alert = response.parse() # get the object that `alerts.create()` would have returned | ||
print(alert.data) | ||
contract = response.parse() # get the object that `contracts.create()` would have returned | ||
print(contract.data) | ||
``` | ||
|
||
These methods return an [`APIResponse`](https://github.com/Metronome-Industries/metronome-python/tree/main/src/metronome/_response.py) object. | ||
|
@@ -248,10 +313,9 @@ 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.alerts.with_streaming_response.create( | ||
alert_type="spend_threshold_reached", | ||
name="$100 spend threshold reached", | ||
threshold=10000, | ||
with client.contracts.with_streaming_response.create( | ||
customer_id="13117714-3f05-48e5-a6e9-a66093f13b4d", | ||
starting_at=parse_datetime("2020-01-01T00:00:00.000Z"), | ||
) as response: | ||
print(response.headers.get("X-My-Header")) | ||
|
||
|
Empty file.
Oops, something went wrong.