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 .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.123.0"
".": "0.124.0"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 190
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic/lithic-0f374e78a0212145a2f55a55dfc39a612de19094d5152ae26b1bc74b01b9e343.yml
openapi_spec_hash: ec888cdaebea979a2cd6231ca04c346c
config_hash: 01dfc901bb6d54b0f582155d779bcbe0
configured_endpoints: 192
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic/lithic-00f07b0edcc0c3c5ef79920ced7f58dac2434df5e4c27ff6041783e8228315f9.yml
openapi_spec_hash: 963688b09480159a06865075c94a2577
config_hash: 265a2b679964f4ad5706de101ad2a942
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.124.0 (2026-05-11)

Full Changelog: [v0.123.0...v0.124.0](https://github.com/lithic-com/lithic-python/compare/v0.123.0...v0.124.0)

### Features

* **api:** add retrieve_signals method to accounts and cards ([6e1649a](https://github.com/lithic-com/lithic-python/commit/6e1649ad7ee7ca58316891747b24c3f4773553d9))
* **api:** add unit parameter and travel/distance attributes to auth_rules ([02bd0f0](https://github.com/lithic-com/lithic-python/commit/02bd0f021353f6ddb9e930f3e5515c0636adfb29))
* **internal/types:** support eagerly validating pydantic iterators ([e956125](https://github.com/lithic-com/lithic-python/commit/e956125636a2734501d5fb3a46de532102a00e87))


### Bug Fixes

* **client:** add missing f-string prefix in file type error message ([826938a](https://github.com/lithic-com/lithic-python/commit/826938aec1590a333b0e377dc6f99c9e14e96cdf))

## 0.123.0 (2026-05-06)

Full Changelog: [v0.122.0...v0.123.0](https://github.com/lithic-com/lithic-python/compare/v0.122.0...v0.123.0)
Expand Down
8 changes: 8 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Methods:
- <code title="get /v1/accounts/{account_token}">client.accounts.<a href="./src/lithic/resources/accounts.py">retrieve</a>(account_token) -> <a href="./src/lithic/types/account.py">Account</a></code>
- <code title="patch /v1/accounts/{account_token}">client.accounts.<a href="./src/lithic/resources/accounts.py">update</a>(account_token, \*\*<a href="src/lithic/types/account_update_params.py">params</a>) -> <a href="./src/lithic/types/account.py">Account</a></code>
- <code title="get /v1/accounts">client.accounts.<a href="./src/lithic/resources/accounts.py">list</a>(\*\*<a href="src/lithic/types/account_list_params.py">params</a>) -> <a href="./src/lithic/types/account.py">SyncCursorPage[Account]</a></code>
- <code title="get /v1/accounts/{account_token}/signals">client.accounts.<a href="./src/lithic/resources/accounts.py">retrieve_signals</a>(account_token) -> <a href="./src/lithic/types/signals_response.py">SignalsResponse</a></code>
- <code title="get /v1/accounts/{account_token}/spend_limits">client.accounts.<a href="./src/lithic/resources/accounts.py">retrieve_spend_limits</a>(account_token) -> <a href="./src/lithic/types/account_spend_limits.py">AccountSpendLimits</a></code>

# AccountHolders
Expand Down Expand Up @@ -88,6 +89,12 @@ Methods:

# AuthRules

Types:

```python
from lithic.types import SignalsResponse
```

## V2

Types:
Expand Down Expand Up @@ -233,6 +240,7 @@ Methods:
- <code title="post /v1/cards/{card_token}/provision">client.cards.<a href="./src/lithic/resources/cards/cards.py">provision</a>(card_token, \*\*<a href="src/lithic/types/card_provision_params.py">params</a>) -> <a href="./src/lithic/types/card_provision_response.py">CardProvisionResponse</a></code>
- <code title="post /v1/cards/{card_token}/reissue">client.cards.<a href="./src/lithic/resources/cards/cards.py">reissue</a>(card_token, \*\*<a href="src/lithic/types/card_reissue_params.py">params</a>) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="post /v1/cards/{card_token}/renew">client.cards.<a href="./src/lithic/resources/cards/cards.py">renew</a>(card_token, \*\*<a href="src/lithic/types/card_renew_params.py">params</a>) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="get /v1/cards/{card_token}/signals">client.cards.<a href="./src/lithic/resources/cards/cards.py">retrieve_signals</a>(card_token) -> <a href="./src/lithic/types/signals_response.py">SignalsResponse</a></code>
- <code title="get /v1/cards/{card_token}/spend_limits">client.cards.<a href="./src/lithic/resources/cards/cards.py">retrieve_spend_limits</a>(card_token) -> <a href="./src/lithic/types/card_spend_limits.py">CardSpendLimits</a></code>
- <code title="post /v1/cards/search_by_pan">client.cards.<a href="./src/lithic/resources/cards/cards.py">search_by_pan</a>(\*\*<a href="src/lithic/types/card_search_by_pan_params.py">params</a>) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="post /v1/cards/{card_token}/web_provision">client.cards.<a href="./src/lithic/resources/cards/cards.py">web_provision</a>(card_token, \*\*<a href="src/lithic/types/card_web_provision_params.py">params</a>) -> <a href="./src/lithic/types/card_web_provision_response.py">CardWebProvisionResponse</a></code>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "lithic"
version = "0.123.0"
version = "0.124.0"
description = "The official Python library for the lithic API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles
elif is_sequence_t(files):
files = [(key, await _async_transform_file(file)) for key, file in files]
else:
raise TypeError("Unexpected file type input {type(files)}, expected mapping or sequence")
raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence")

return files

Expand Down
80 changes: 80 additions & 0 deletions src/lithic/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
ClassVar,
Protocol,
Required,
Annotated,
ParamSpec,
TypeAlias,
TypedDict,
TypeGuard,
final,
Expand Down Expand Up @@ -79,7 +81,15 @@
from ._constants import RAW_RESPONSE_HEADER

if TYPE_CHECKING:
from pydantic import GetCoreSchemaHandler, ValidatorFunctionWrapHandler
from pydantic_core import CoreSchema, core_schema
from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema
else:
try:
from pydantic_core import CoreSchema, core_schema
except ImportError:
CoreSchema = None
core_schema = None

__all__ = ["BaseModel", "GenericModel"]

Expand Down Expand Up @@ -396,6 +406,76 @@ def model_dump_json(
)


class _EagerIterable(list[_T], Generic[_T]):
"""
Accepts any Iterable[T] input (including generators), consumes it
eagerly, and validates all items upfront.

Validation preserves the original container type where possible
(e.g. a set[T] stays a set[T]). Serialization (model_dump / JSON)
always emits a list — round-tripping through model_dump() will not
restore the original container type.
"""

@classmethod
def __get_pydantic_core_schema__(
cls,
source_type: Any,
handler: GetCoreSchemaHandler,
) -> CoreSchema:
(item_type,) = get_args(source_type) or (Any,)
item_schema: CoreSchema = handler.generate_schema(item_type)
list_of_items_schema: CoreSchema = core_schema.list_schema(item_schema)

return core_schema.no_info_wrap_validator_function(
cls._validate,
list_of_items_schema,
serialization=core_schema.plain_serializer_function_ser_schema(
cls._serialize,
info_arg=False,
),
)

@staticmethod
def _validate(v: Iterable[_T], handler: "ValidatorFunctionWrapHandler") -> Any:
original_type: type[Any] = type(v)

# Normalize to list so list_schema can validate each item
if isinstance(v, list):
items: list[_T] = v
else:
try:
items = list(v)
except TypeError as e:
raise TypeError("Value is not iterable") from e

# Validate items against the inner schema
validated: list[_T] = handler(items)

# Reconstruct original container type
if original_type is list:
return validated
# str(list) produces the list's repr, not a string built from items,
# so skip reconstruction for str and its subclasses.
if issubclass(original_type, str):
return validated
try:
return original_type(validated)
except (TypeError, ValueError):
# If the type cannot be reconstructed, just return the validated list
return validated

@staticmethod
def _serialize(v: Iterable[_T]) -> list[_T]:
"""Always serialize as a list so Pydantic's JSON encoder is happy."""
if isinstance(v, list):
return v
return list(v)


EagerIterable: TypeAlias = Annotated[Iterable[_T], _EagerIterable]


def _construct_field(value: object, field: FieldInfo, key: str) -> object:
if value is None:
return field_get_default(field)
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "lithic"
__version__ = "0.123.0" # x-release-please-version
__version__ = "0.124.0" # x-release-please-version
93 changes: 93 additions & 0 deletions src/lithic/resources/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..pagination import SyncCursorPage, AsyncCursorPage
from .._base_client import AsyncPaginator, make_request_options
from ..types.account import Account
from ..types.signals_response import SignalsResponse
from ..types.account_spend_limits import AccountSpendLimits

__all__ = ["Accounts", "AsyncAccounts"]
Expand Down Expand Up @@ -259,6 +260,46 @@ def list(
model=Account,
)

def retrieve_signals(
self,
account_token: str,
*,
# 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.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SignalsResponse:
"""
Returns behavioral feature state derived from an account's transaction history.

These signals expose the same data used by behavioral rule attributes (e.g.
`AMOUNT_Z_SCORE` with `scope: ACCOUNT`, `IS_NEW_COUNTRY` with `scope: ACCOUNT`)
and custom code `TRANSACTION_HISTORY_SIGNALS` features, allowing clients to
inspect feature values before writing rules and debug rule behavior.

Note: 3DS fields are not available at the account scope and will be null.

Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_token:
raise ValueError(f"Expected a non-empty value for `account_token` but received {account_token!r}")
return self._get(
path_template("/v1/accounts/{account_token}/signals", account_token=account_token),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=SignalsResponse,
)

def retrieve_spend_limits(
self,
account_token: str,
Expand Down Expand Up @@ -533,6 +574,46 @@ def list(
model=Account,
)

async def retrieve_signals(
self,
account_token: str,
*,
# 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.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SignalsResponse:
"""
Returns behavioral feature state derived from an account's transaction history.

These signals expose the same data used by behavioral rule attributes (e.g.
`AMOUNT_Z_SCORE` with `scope: ACCOUNT`, `IS_NEW_COUNTRY` with `scope: ACCOUNT`)
and custom code `TRANSACTION_HISTORY_SIGNALS` features, allowing clients to
inspect feature values before writing rules and debug rule behavior.

Note: 3DS fields are not available at the account scope and will be null.

Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_token:
raise ValueError(f"Expected a non-empty value for `account_token` but received {account_token!r}")
return await self._get(
path_template("/v1/accounts/{account_token}/signals", account_token=account_token),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=SignalsResponse,
)

async def retrieve_spend_limits(
self,
account_token: str,
Expand Down Expand Up @@ -584,6 +665,9 @@ def __init__(self, accounts: Accounts) -> None:
self.list = _legacy_response.to_raw_response_wrapper(
accounts.list,
)
self.retrieve_signals = _legacy_response.to_raw_response_wrapper(
accounts.retrieve_signals,
)
self.retrieve_spend_limits = _legacy_response.to_raw_response_wrapper(
accounts.retrieve_spend_limits,
)
Expand All @@ -602,6 +686,9 @@ def __init__(self, accounts: AsyncAccounts) -> None:
self.list = _legacy_response.async_to_raw_response_wrapper(
accounts.list,
)
self.retrieve_signals = _legacy_response.async_to_raw_response_wrapper(
accounts.retrieve_signals,
)
self.retrieve_spend_limits = _legacy_response.async_to_raw_response_wrapper(
accounts.retrieve_spend_limits,
)
Expand All @@ -620,6 +707,9 @@ def __init__(self, accounts: Accounts) -> None:
self.list = to_streamed_response_wrapper(
accounts.list,
)
self.retrieve_signals = to_streamed_response_wrapper(
accounts.retrieve_signals,
)
self.retrieve_spend_limits = to_streamed_response_wrapper(
accounts.retrieve_spend_limits,
)
Expand All @@ -638,6 +728,9 @@ def __init__(self, accounts: AsyncAccounts) -> None:
self.list = async_to_streamed_response_wrapper(
accounts.list,
)
self.retrieve_signals = async_to_streamed_response_wrapper(
accounts.retrieve_signals,
)
self.retrieve_spend_limits = async_to_streamed_response_wrapper(
accounts.retrieve_spend_limits,
)
Loading