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.122.0"
".": "0.123.0"
}
6 changes: 3 additions & 3 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%2Flithic-d29b68bb85936070878d8badaa8a7c5991313285e70a990bc812c838eba85373.yml
openapi_spec_hash: 54b44da68df22eb0ea99f2bc564667a2
config_hash: ac8326134e692f3f3bdec82396bbec80
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic/lithic-0f374e78a0212145a2f55a55dfc39a612de19094d5152ae26b1bc74b01b9e343.yml
openapi_spec_hash: ec888cdaebea979a2cd6231ca04c346c
config_hash: 01dfc901bb6d54b0f582155d779bcbe0
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## 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)

### Features

* **api:** add AMEX to network enum in settlement reports ([a429a2e](https://github.com/lithic-com/lithic-python/commit/a429a2e6c8915f857d692f567951b03b392791ba))
* **api:** add CARD_TRANSACTION_UPDATE event stream and action params to auth_rules v2 ([0f09b01](https://github.com/lithic-com/lithic-python/commit/0f09b0181efbb024fd9559995b166865e5eb1cc8))
* **api:** add IS_NEW_MERCHANT to auth_rules conditional authorization conditions ([7bdb5aa](https://github.com/lithic-com/lithic-python/commit/7bdb5aa9c3370da6f1a2eafa268ae235c7b036a1))
* support setting headers via env ([759b6e2](https://github.com/lithic-com/lithic-python/commit/759b6e2ea428bfea52d518cd9dadadac4d4bc393))


### Bug Fixes

* **types:** make substatus/funding optional, add exemption_type enum value ([e424839](https://github.com/lithic-com/lithic-python/commit/e424839de5a127d48086c9dd1ed5ec7146cdfd6a))
* use correct field name format for multipart file arrays ([66cbc65](https://github.com/lithic-com/lithic-python/commit/66cbc65975b11d4914b4f3c57b4b7b581cef04d7))


### Chores

* **internal:** more robust bootstrap script ([0df0d6c](https://github.com/lithic-com/lithic-python/commit/0df0d6cf2e2691b4979e5727dd88781229b7e831))
* **internal:** reformat pyproject.toml ([7d42546](https://github.com/lithic-com/lithic-python/commit/7d4254692e5456f270de6173ba45180b3adfcb66))


### Documentation

* **api:** clarify exp_month/exp_year generation in cards create/renew methods ([8e94d66](https://github.com/lithic-com/lithic-python/commit/8e94d661759140b25e202afb48fd00ac63bf68d4))
* **types:** improve settlement_detail field descriptions ([77ee726](https://github.com/lithic-com/lithic-python/commit/77ee72643eebfa74b7a97d8e4104e3fd5be21041))

## 0.122.0 (2026-04-20)

Full Changelog: [v0.121.0...v0.122.0](https://github.com/lithic-com/lithic-python/compare/v0.121.0...v0.122.0)
Expand Down
3 changes: 3 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,21 @@ from lithic.types.auth_rules import (
AuthRuleCondition,
AuthRuleVersion,
BacktestStats,
CardTransactionUpdateAction,
Conditional3DSActionParameters,
ConditionalACHActionParameters,
ConditionalAttribute,
ConditionalAuthorizationActionParameters,
ConditionalBlockParameters,
ConditionalCardTransactionUpdateActionParameters,
ConditionalOperation,
ConditionalTokenizationActionParameters,
ConditionalValue,
EventStream,
MerchantLockParameters,
ReportStats,
RuleFeature,
SpendVelocityFilters,
TypescriptCodeParameters,
VelocityLimitFilters,
VelocityLimitParams,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "lithic"
version = "0.122.0"
version = "0.123.0"
description = "The official Python library for the lithic API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -170,7 +170,7 @@ show_error_codes = true
#
# We also exclude our `tests` as mypy doesn't always infer
# types correctly and Pyright will still catch any type errors.
exclude = ['src/lithic/_files.py', '_dev/.*.py', 'tests/.*']
exclude = ["src/lithic/_files.py", "_dev/.*.py", "tests/.*"]

strict_equality = true
implicit_reexport = true
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

cd "$(dirname "$0")/.."

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then
brew bundle check >/dev/null 2>&1 || {
echo -n "==> Install Homebrew dependencies? (y/N): "
read -r response
Expand Down
24 changes: 23 additions & 1 deletion src/lithic/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
RequestOptions,
not_given,
)
from ._utils import is_given, get_async_library
from ._utils import (
is_given,
is_mapping_t,
get_async_library,
)
from ._compat import cached_property
from ._version import __version__
from ._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
Expand Down Expand Up @@ -197,6 +201,15 @@ def __init__(
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc

custom_headers_env = os.environ.get("LITHIC_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down Expand Up @@ -612,6 +625,15 @@ def __init__(
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc

custom_headers_env = os.environ.get("LITHIC_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down
8 changes: 2 additions & 6 deletions src/lithic/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

from typing import Any, List, Tuple, Union, Mapping, TypeVar
from urllib.parse import parse_qs, urlencode
from typing_extensions import Literal, get_args
from typing_extensions import get_args

from ._types import NotGiven, not_given
from ._types import NotGiven, ArrayFormat, NestedFormat, not_given
from ._utils import flatten

_T = TypeVar("_T")


ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]

PrimitiveData = Union[str, int, float, bool, None]
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
# https://github.com/microsoft/pyright/issues/3555
Expand Down
3 changes: 3 additions & 0 deletions src/lithic/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
_T = TypeVar("_T")

ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]


# Approximates httpx internal ProxiesTypes and RequestFiles types
# while adding support for `PathLike` instances
Expand Down
42 changes: 34 additions & 8 deletions src/lithic/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
)
from pathlib import Path
from datetime import date, datetime
from typing_extensions import TypeGuard
from typing_extensions import TypeGuard, get_args

import sniffio

from .._types import Omit, NotGiven, FileTypes, HeadersLike
from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike

_T = TypeVar("_T")
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
Expand All @@ -40,25 +40,45 @@ def extract_files(
query: Mapping[str, object],
*,
paths: Sequence[Sequence[str]],
array_format: ArrayFormat = "brackets",
) -> list[tuple[str, FileTypes]]:
"""Recursively extract files from the given dictionary based on specified paths.

A path may look like this ['foo', 'files', '<array>', 'data'].

``array_format`` controls how ``<array>`` segments contribute to the emitted
field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and
``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``).

Note: this mutates the given dictionary.
"""
files: list[tuple[str, FileTypes]] = []
for path in paths:
files.extend(_extract_items(query, path, index=0, flattened_key=None))
files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format))
return files


def _array_suffix(array_format: ArrayFormat, array_index: int) -> str:
if array_format == "brackets":
return "[]"
if array_format == "indices":
return f"[{array_index}]"
if array_format == "repeat" or array_format == "comma":
# Both repeat the bare field name for each file part; there is no
# meaningful way to comma-join binary parts.
return ""
raise NotImplementedError(
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
)


def _extract_items(
obj: object,
path: Sequence[str],
*,
index: int,
flattened_key: str | None,
array_format: ArrayFormat,
) -> list[tuple[str, FileTypes]]:
try:
key = path[index]
Expand All @@ -75,9 +95,11 @@ def _extract_items(

if is_list(obj):
files: list[tuple[str, FileTypes]] = []
for entry in obj:
assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "")
files.append((flattened_key + "[]", cast(FileTypes, entry)))
for array_index, entry in enumerate(obj):
suffix = _array_suffix(array_format, array_index)
emitted_key = (flattened_key + suffix) if flattened_key else suffix
assert_is_file_content(entry, key=emitted_key)
files.append((emitted_key, cast(FileTypes, entry)))
return files

assert_is_file_content(obj, key=flattened_key)
Expand Down Expand Up @@ -106,6 +128,7 @@ def _extract_items(
path,
index=index,
flattened_key=flattened_key,
array_format=array_format,
)
elif is_list(obj):
if key != "<array>":
Expand All @@ -117,9 +140,12 @@ def _extract_items(
item,
path,
index=index,
flattened_key=flattened_key + "[]" if flattened_key is not None else "[]",
flattened_key=(
(flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index)
),
array_format=array_format,
)
for item in obj
for array_index, item in enumerate(obj)
]
)

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.122.0" # x-release-please-version
__version__ = "0.123.0" # x-release-please-version
42 changes: 23 additions & 19 deletions src/lithic/resources/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Union
from typing import Union, Optional
from datetime import datetime
from typing_extensions import Literal

Expand Down Expand Up @@ -85,15 +85,17 @@ def update(
lifetime_spend_limit: int | Omit = omit,
monthly_spend_limit: int | Omit = omit,
state: Literal["ACTIVE", "PAUSED", "CLOSED"] | Omit = omit,
substatus: Literal[
"FRAUD_IDENTIFIED",
"SUSPICIOUS_ACTIVITY",
"RISK_VIOLATION",
"END_USER_REQUEST",
"ISSUER_REQUEST",
"NOT_ACTIVE",
"INTERNAL_REVIEW",
"OTHER",
substatus: Optional[
Literal[
"FRAUD_IDENTIFIED",
"SUSPICIOUS_ACTIVITY",
"RISK_VIOLATION",
"END_USER_REQUEST",
"ISSUER_REQUEST",
"NOT_ACTIVE",
"INTERNAL_REVIEW",
"OTHER",
]
]
| Omit = omit,
verification_address: account_update_params.VerificationAddress | Omit = omit,
Expand Down Expand Up @@ -357,15 +359,17 @@ async def update(
lifetime_spend_limit: int | Omit = omit,
monthly_spend_limit: int | Omit = omit,
state: Literal["ACTIVE", "PAUSED", "CLOSED"] | Omit = omit,
substatus: Literal[
"FRAUD_IDENTIFIED",
"SUSPICIOUS_ACTIVITY",
"RISK_VIOLATION",
"END_USER_REQUEST",
"ISSUER_REQUEST",
"NOT_ACTIVE",
"INTERNAL_REVIEW",
"OTHER",
substatus: Optional[
Literal[
"FRAUD_IDENTIFIED",
"SUSPICIOUS_ACTIVITY",
"RISK_VIOLATION",
"END_USER_REQUEST",
"ISSUER_REQUEST",
"NOT_ACTIVE",
"INTERNAL_REVIEW",
"OTHER",
]
]
| Omit = omit,
verification_address: account_update_params.VerificationAddress | Omit = omit,
Expand Down
18 changes: 12 additions & 6 deletions src/lithic/resources/auth_rules/v2/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def create(
- `VELOCITY_LIMIT`: AUTHORIZATION event stream.
- `MERCHANT_LOCK`: AUTHORIZATION event stream.
- `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
ACH_CREDIT_RECEIPT, ACH_DEBIT_RECEIPT, or CARD_TRANSACTION_UPDATE event
stream.
- `TYPESCRIPT_CODE`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.

Expand Down Expand Up @@ -157,7 +158,8 @@ def create(
- `VELOCITY_LIMIT`: AUTHORIZATION event stream.
- `MERCHANT_LOCK`: AUTHORIZATION event stream.
- `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
ACH_CREDIT_RECEIPT, ACH_DEBIT_RECEIPT, or CARD_TRANSACTION_UPDATE event
stream.
- `TYPESCRIPT_CODE`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.

Expand Down Expand Up @@ -212,7 +214,8 @@ def create(
- `VELOCITY_LIMIT`: AUTHORIZATION event stream.
- `MERCHANT_LOCK`: AUTHORIZATION event stream.
- `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
ACH_CREDIT_RECEIPT, ACH_DEBIT_RECEIPT, or CARD_TRANSACTION_UPDATE event
stream.
- `TYPESCRIPT_CODE`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.

Expand Down Expand Up @@ -979,7 +982,8 @@ async def create(
- `VELOCITY_LIMIT`: AUTHORIZATION event stream.
- `MERCHANT_LOCK`: AUTHORIZATION event stream.
- `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
ACH_CREDIT_RECEIPT, ACH_DEBIT_RECEIPT, or CARD_TRANSACTION_UPDATE event
stream.
- `TYPESCRIPT_CODE`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.

Expand Down Expand Up @@ -1035,7 +1039,8 @@ async def create(
- `VELOCITY_LIMIT`: AUTHORIZATION event stream.
- `MERCHANT_LOCK`: AUTHORIZATION event stream.
- `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
ACH_CREDIT_RECEIPT, ACH_DEBIT_RECEIPT, or CARD_TRANSACTION_UPDATE event
stream.
- `TYPESCRIPT_CODE`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.

Expand Down Expand Up @@ -1090,7 +1095,8 @@ async def create(
- `VELOCITY_LIMIT`: AUTHORIZATION event stream.
- `MERCHANT_LOCK`: AUTHORIZATION event stream.
- `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
ACH_CREDIT_RECEIPT, ACH_DEBIT_RECEIPT, or CARD_TRANSACTION_UPDATE event
stream.
- `TYPESCRIPT_CODE`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.

Expand Down
Loading