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"
}
4 changes: 2 additions & 2 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
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-d6101c64c957742cde9cfdc5d9213ce4e36aa43d045030fa142e27a46b60884a.yml
openapi_spec_hash: b615a0eb16502b4de874f9ae28491894
config_hash: ac8326134e692f3f3bdec82396bbec80
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 0.123.0 (2026-04-28)

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


### Documentation

* **api:** clarify exp_month/exp_year generation in cards create/renew methods ([8e94d66](https://github.com/lithic-com/lithic-python/commit/8e94d661759140b25e202afb48fd00ac63bf68d4))

## 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
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.122.0"
version = "0.123.0"
description = "The official Python library for the lithic API"
dynamic = ["readme"]
license = "Apache-2.0"
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
24 changes: 16 additions & 8 deletions src/lithic/resources/cards/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ def create(
[Flexible Card Art Guide](https://docs.lithic.com/docs/about-digital-wallets#flexible-card-art).

exp_month: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
an expiration date will be generated.
an expiration date five years in the future will be generated. Five years is the
maximum expiration date.

exp_year: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is
provided, an expiration date will be generated.
provided, an expiration date five years in the future will be generated. Five
years is the maximum expiration date.

memo: Friendly name to identify the card.

Expand Down Expand Up @@ -1051,10 +1053,12 @@ def renew(
carrier: If omitted, the previous carrier will be used.

exp_month: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
an expiration date six years in the future will be generated.
an expiration date five years in the future will be generated. Five years is the
maximum expiration date.

exp_year: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is
provided, an expiration date six years in the future will be generated.
provided, an expiration date five years in the future will be generated. Five
years is the maximum expiration date.

product_id: Specifies the configuration (e.g. physical card art) that the card should be
manufactured with, and only applies to cards of type `PHYSICAL`. This must be
Expand Down Expand Up @@ -1369,10 +1373,12 @@ async def create(
[Flexible Card Art Guide](https://docs.lithic.com/docs/about-digital-wallets#flexible-card-art).

exp_month: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
an expiration date will be generated.
an expiration date five years in the future will be generated. Five years is the
maximum expiration date.

exp_year: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is
provided, an expiration date will be generated.
provided, an expiration date five years in the future will be generated. Five
years is the maximum expiration date.

memo: Friendly name to identify the card.

Expand Down Expand Up @@ -2237,10 +2243,12 @@ async def renew(
carrier: If omitted, the previous carrier will be used.

exp_month: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
an expiration date six years in the future will be generated.
an expiration date five years in the future will be generated. Five years is the
maximum expiration date.

exp_year: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is
provided, an expiration date six years in the future will be generated.
provided, an expiration date five years in the future will be generated. Five
years is the maximum expiration date.

product_id: Specifies the configuration (e.g. physical card art) that the card should be
manufactured with, and only applies to cards of type `PHYSICAL`. This must be
Expand Down
4 changes: 2 additions & 2 deletions src/lithic/resources/reports/settlement/network_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def list(
end: Union[str, datetime] | Omit = omit,
ending_before: str | Omit = omit,
institution_id: str | Omit = omit,
network: Literal["VISA", "MASTERCARD", "MAESTRO", "INTERLINK"] | Omit = omit,
network: Literal["AMEX", "VISA", "MASTERCARD", "MAESTRO", "INTERLINK"] | Omit = omit,
page_size: int | Omit = omit,
report_date: Union[str, date] | Omit = omit,
report_date_begin: Union[str, date] | Omit = omit,
Expand Down Expand Up @@ -227,7 +227,7 @@ def list(
end: Union[str, datetime] | Omit = omit,
ending_before: str | Omit = omit,
institution_id: str | Omit = omit,
network: Literal["VISA", "MASTERCARD", "MAESTRO", "INTERLINK"] | Omit = omit,
network: Literal["AMEX", "VISA", "MASTERCARD", "MAESTRO", "INTERLINK"] | Omit = omit,
page_size: int | Omit = omit,
report_date: Union[str, date] | Omit = omit,
report_date_begin: Union[str, date] | Omit = omit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class AccountHolderSimulateEnrollmentReviewResponse(BaseModel):
exemption_type: Optional[Literal["AUTHORIZED_USER", "PREPAID_CARD_USER"]] = None
"""The type of KYC exemption for a KYC-Exempt Account Holder.

"None" if the account holder is not KYC-Exempt.
`null` if the account holder is not KYC-Exempt.
"""

external_id: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/types/account_holder_update_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class KYBKYCPatchResponse(BaseModel):
exemption_type: Optional[Literal["AUTHORIZED_USER", "PREPAID_CARD_USER"]] = None
"""The type of KYC exemption for a KYC-Exempt Account Holder.

"None" if the account holder is not KYC-Exempt.
`null` if the account holder is not KYC-Exempt.
"""

external_id: Optional[str] = None
Expand Down
Loading