Skip to content
Open
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
2 changes: 1 addition & 1 deletion .fern/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"use_typeddict_requests_for_file_upload": true,
"exclude_types_from_init_exports": true
},
"sdkVersion": "44.1.0.20260520"
"sdkVersion": "44.2.0.20260520"
}
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ examples
legacy
src/square/core/api_error.py
src/square/utils/webhooks_helper.py
src/square/utils/reporting_helper.py
tests/integration
README.md
.fern/replay.lock
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
runs-on: ubuntu-latest
env:
TEST_SQUARE_TOKEN: ${{ secrets.TEST_SQUARE_TOKEN }}
TEST_SQUARE_REPORTING: ${{ secrets.TEST_SQUARE_REPORTING }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,71 @@ is_valid = verify_signature(
)
```

## Reporting API

The [Reporting API](https://developer.squareup.com/docs/reporting-api/overview) lets you query
aggregated reporting data. Call `reporting.get_metadata` first to discover the available cubes,
measures, and dimensions, then run a query with `reporting.load`.

```python
from square import Square

client = Square(token="YOUR_TOKEN")

# Discover what you can query.
metadata = client.reporting.get_metadata()

# Run a query against the discovered schema.
response = client.reporting.load(query={"measures": ["Orders.count"]})
```

`load` is asynchronous: while a query is still being computed, the API returns an HTTP `200` whose
body is `{"error": "Continue wait"}` instead of results, and the client is expected to re-send the
identical request — with backoff — until the results are ready. The `load_and_wait` helper owns
that polling loop for you and returns the resolved results (never the `"Continue wait"` sentinel):

```python
from square import Square
from square.utils.reporting_helper import load_and_wait

client = Square(token="YOUR_TOKEN")

response = load_and_wait(client, query={"measures": ["Orders.count"]})

print(response.results)
```

By default it polls up to 20 times with exponential backoff (2s → 20s). Tune the behavior — and
pass a `threading.Event` to cancel — via the keyword arguments:

```python
import threading

cancel_event = threading.Event()

response = load_and_wait(
client,
query={"measures": ["Orders.count"]},
max_attempts=10, # default 20
initial_delay_s=1.0, # default 2.0
max_delay_s=20.0, # default 20.0
backoff_factor=2.0, # default 2.0
cancel_event=cancel_event,
)
```

For the [async client](#async-client), use `load_and_wait_async` (cancel it the idiomatic asyncio
way — e.g. `asyncio.wait_for` or `Task.cancel`):

```python
from square import AsyncSquare
from square.utils.reporting_helper import load_and_wait_async

client = AsyncSquare(token="YOUR_TOKEN")

response = await load_and_wait_async(client, query={"measures": ["Orders.count"]})
```

## Advanced

### Retries
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dynamic = ["version"]

[tool.poetry]
name = "squareup"
version = "44.1.0.20260520"
version = "44.2.0.20260520"
description = ""
readme = "README.md"
authors = []
Expand Down
145 changes: 145 additions & 0 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -18511,6 +18511,151 @@ information.
</dl>


</dd>
</dl>
</details>

## Reporting
<details><summary><code>client.reporting.<a href="src/square/reporting/client.py">get_metadata</a>() -&gt; AsyncHttpResponse[MetadataResponse]</code></summary>
<dl>
<dd>

#### 📝 Description

<dl>
<dd>

<dl>
<dd>

Describes the data available to query: the cubes, views, measures, dimensions, and segments you can reference in a reporting query. Call this first to discover the schema, then pass the members you need to `load`.
</dd>
</dl>
</dd>
</dl>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```python
from square import Square

client = Square(
token="YOUR_TOKEN",
)
client.reporting.get_metadata()

```
</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.

</dd>
</dl>
</dd>
</dl>


</dd>
</dl>
</details>

<details><summary><code>client.reporting.<a href="src/square/reporting/client.py">load</a>(...) -&gt; AsyncHttpResponse[LoadResponse]</code></summary>
<dl>
<dd>

#### 📝 Description

<dl>
<dd>

<dl>
<dd>

Runs a reporting query against the discovered schema and returns the aggregated results. Long-running queries may return a "Continue wait" response while processing — retry the same request until results are ready.
</dd>
</dl>
</dd>
</dl>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```python
from square import Square

client = Square(
token="YOUR_TOKEN",
)
client.reporting.load()

```
</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**query_type:** `typing.Optional[str]`

</dd>
</dl>

<dl>
<dd>

**cache:** `typing.Optional[CacheMode]`

</dd>
</dl>

<dl>
<dd>

**query:** `typing.Optional[QueryParams]`

</dd>
</dl>

<dl>
<dd>

**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.

</dd>
</dl>
</dd>
</dl>


</dd>
</dl>
</details>
Expand Down
3 changes: 3 additions & 0 deletions src/square/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
payments,
payouts,
refunds,
reporting,
sites,
snippets,
subscriptions,
Expand Down Expand Up @@ -74,6 +75,7 @@
"payments": ".payments",
"payouts": ".payouts",
"refunds": ".refunds",
"reporting": ".reporting",
"sites": ".sites",
"snippets": ".snippets",
"subscriptions": ".subscriptions",
Expand Down Expand Up @@ -137,6 +139,7 @@ def __dir__():
"payments",
"payouts",
"refunds",
"reporting",
"sites",
"snippets",
"subscriptions",
Expand Down
19 changes: 19 additions & 0 deletions src/square/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .payments.client import AsyncPaymentsClient, PaymentsClient
from .payouts.client import AsyncPayoutsClient, PayoutsClient
from .refunds.client import AsyncRefundsClient, RefundsClient
from .reporting.client import AsyncReportingClient, ReportingClient
from .sites.client import AsyncSitesClient, SitesClient
from .snippets.client import AsyncSnippetsClient, SnippetsClient
from .subscriptions.client import AsyncSubscriptionsClient, SubscriptionsClient
Expand Down Expand Up @@ -148,6 +149,7 @@ def __init__(
self._terminal: typing.Optional[TerminalClient] = None
self._transfer_orders: typing.Optional[TransferOrdersClient] = None
self._vendors: typing.Optional[VendorsClient] = None
self._reporting: typing.Optional[ReportingClient] = None
self._cash_drawers: typing.Optional[CashDrawersClient] = None
self._webhooks: typing.Optional[WebhooksClient] = None

Expand Down Expand Up @@ -415,6 +417,14 @@ def vendors(self):
self._vendors = VendorsClient(client_wrapper=self._client_wrapper)
return self._vendors

@property
def reporting(self):
if self._reporting is None:
from .reporting.client import ReportingClient # noqa: E402

self._reporting = ReportingClient(client_wrapper=self._client_wrapper)
return self._reporting

@property
def cash_drawers(self):
if self._cash_drawers is None:
Expand Down Expand Up @@ -533,6 +543,7 @@ def __init__(
self._terminal: typing.Optional[AsyncTerminalClient] = None
self._transfer_orders: typing.Optional[AsyncTransferOrdersClient] = None
self._vendors: typing.Optional[AsyncVendorsClient] = None
self._reporting: typing.Optional[AsyncReportingClient] = None
self._cash_drawers: typing.Optional[AsyncCashDrawersClient] = None
self._webhooks: typing.Optional[AsyncWebhooksClient] = None

Expand Down Expand Up @@ -800,6 +811,14 @@ def vendors(self):
self._vendors = AsyncVendorsClient(client_wrapper=self._client_wrapper)
return self._vendors

@property
def reporting(self):
if self._reporting is None:
from .reporting.client import AsyncReportingClient # noqa: E402

self._reporting = AsyncReportingClient(client_wrapper=self._client_wrapper)
return self._reporting

@property
def cash_drawers(self):
if self._cash_drawers is None:
Expand Down
4 changes: 2 additions & 2 deletions src/square/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def get_headers(self) -> typing.Dict[str, str]:
import platform

headers: typing.Dict[str, str] = {
"User-Agent": "squareup/44.1.0.20260520",
"User-Agent": "squareup/44.2.0.20260520",
"X-Fern-Language": "Python",
"X-Fern-Runtime": f"python/{platform.python_version()}",
"X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
"X-Fern-SDK-Name": "squareup",
"X-Fern-SDK-Version": "44.1.0.20260520",
"X-Fern-SDK-Version": "44.2.0.20260520",
**(self.get_custom_headers() or {}),
}
token = self._get_token()
Expand Down
4 changes: 4 additions & 0 deletions src/square/reporting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file was auto-generated by Fern from our API Definition.

# isort: skip_file

Loading
Loading