Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

jobs:
lint:
timeout-minutes: 10
name: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -30,6 +31,7 @@ jobs:
run: ./scripts/lint

test:
timeout-minutes: 10
name: test
runs-on: ubuntu-latest
steps:
Expand All @@ -50,6 +52,7 @@ jobs:
run: ./scripts/test

examples:
timeout-minutes: 10
name: examples
runs-on: ubuntu-latest
if: github.repository == 'lithic-com/lithic-python'
Expand Down
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 156
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-18973e063e9e9233433290bb4d641df8e17e1f21f5b1ec57e00182f0a48dbdec.yml
openapi_spec_hash: ab503dc3772f962b603ade7b91b8534c
config_hash: 6729d695e399d14fff4891b6b82ec86c
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-569e7dcb415398515370989172038db711642cd3b0bd7559bfd2b94e325a6086.yml
openapi_spec_hash: ce1dae8c6eb50d4490e75357c5e520a7
config_hash: e9de93b19060a153a852f7c03f235162
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ client = Lithic()
card = client.cards.create(
type="VIRTUAL",
)
print(card.product_id)
```

## Webhook Verification
Expand Down
3 changes: 2 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Types:
from lithic.types import (
Card,
CardSpendLimits,
NonPCICard,
SpendLimitDuration,
CardEmbedResponse,
CardProvisionResponse,
Expand All @@ -191,7 +192,7 @@ Methods:
- <code title="post /v1/cards">client.cards.<a href="./src/lithic/resources/cards/cards.py">create</a>(\*\*<a href="src/lithic/types/card_create_params.py">params</a>) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="get /v1/cards/{card_token}">client.cards.<a href="./src/lithic/resources/cards/cards.py">retrieve</a>(card_token) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="patch /v1/cards/{card_token}">client.cards.<a href="./src/lithic/resources/cards/cards.py">update</a>(card_token, \*\*<a href="src/lithic/types/card_update_params.py">params</a>) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="get /v1/cards">client.cards.<a href="./src/lithic/resources/cards/cards.py">list</a>(\*\*<a href="src/lithic/types/card_list_params.py">params</a>) -> <a href="./src/lithic/types/card.py">SyncCursorPage[Card]</a></code>
- <code title="get /v1/cards">client.cards.<a href="./src/lithic/resources/cards/cards.py">list</a>(\*\*<a href="src/lithic/types/card_list_params.py">params</a>) -> <a href="./src/lithic/types/non_pci_card.py">SyncCursorPage[NonPCICard]</a></code>
- <code title="post /v1/cards/{card_token}/convert_physical">client.cards.<a href="./src/lithic/resources/cards/cards.py">convert_physical</a>(card_token, \*\*<a href="src/lithic/types/card_convert_physical_params.py">params</a>) -> <a href="./src/lithic/types/card.py">Card</a></code>
- <code title="get /v1/embed/card">client.cards.<a href="./src/lithic/resources/cards/cards.py">embed</a>(\*\*<a href="src/lithic/types/card_embed_params.py">params</a>) -> str</code>
- <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>
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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/.*|src/lithic/resources/external_bank_accounts/external_bank_accounts\.py)$
exclude = ^(src/lithic/_files\.py|_dev/.*\.py|tests/.*)$

strict_equality = True
implicit_reexport = True
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Repository = "https://github.com/lithic-com/lithic-python"
managed = true
# version pins are in requirements-dev.lock
dev-dependencies = [
"pyright>=1.1.359",
"pyright==1.1.399",
"mypy",
"respx",
"pytest",
Expand Down Expand Up @@ -147,11 +147,10 @@ exclude = [
]

reportImplicitOverride = true
reportOverlappingOverload = false

reportImportCycles = false
reportPrivateUsage = false
reportOverlappingOverload = false


[tool.ruff]
line-length = 120
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pydantic-core==2.27.1
# via pydantic
pygments==2.18.0
# via rich
pyright==1.1.392.post0
pyright==1.1.399
pytest==8.3.3
# via pytest-asyncio
pytest-asyncio==0.24.0
Expand Down
42 changes: 40 additions & 2 deletions src/lithic/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@
_AsyncStreamT = TypeVar("_AsyncStreamT", bound=AsyncStream[Any])

if TYPE_CHECKING:
from httpx._config import DEFAULT_TIMEOUT_CONFIG as HTTPX_DEFAULT_TIMEOUT
from httpx._config import (
DEFAULT_TIMEOUT_CONFIG, # pyright: ignore[reportPrivateImportUsage]
)

HTTPX_DEFAULT_TIMEOUT = DEFAULT_TIMEOUT_CONFIG
else:
try:
from httpx._config import DEFAULT_TIMEOUT_CONFIG as HTTPX_DEFAULT_TIMEOUT
Expand All @@ -116,6 +120,7 @@ class PageInfo:

url: URL | NotGiven
params: Query | NotGiven
json: Body | NotGiven

@overload
def __init__(
Expand All @@ -131,19 +136,30 @@ def __init__(
params: Query,
) -> None: ...

@overload
def __init__(
self,
*,
json: Body,
) -> None: ...

def __init__(
self,
*,
url: URL | NotGiven = NOT_GIVEN,
json: Body | NotGiven = NOT_GIVEN,
params: Query | NotGiven = NOT_GIVEN,
) -> None:
self.url = url
self.json = json
self.params = params

@override
def __repr__(self) -> str:
if self.url:
return f"{self.__class__.__name__}(url={self.url})"
if self.json:
return f"{self.__class__.__name__}(json={self.json})"
return f"{self.__class__.__name__}(params={self.params})"


Expand Down Expand Up @@ -192,6 +208,19 @@ def _info_to_options(self, info: PageInfo) -> FinalRequestOptions:
options.url = str(url)
return options

if not isinstance(info.json, NotGiven):
if not is_mapping(info.json):
raise TypeError("Pagination is only supported with mappings")

if not options.json_data:
options.json_data = {**info.json}
else:
if not is_mapping(options.json_data):
raise TypeError("Pagination is only supported with mappings")

options.json_data = {**options.json_data, **info.json}
return options

raise ValueError("Unexpected PageInfo state")


Expand Down Expand Up @@ -410,7 +439,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0

idempotency_header = self._idempotency_header
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
options.idempotency_key = options.idempotency_key or self._idempotency_key()
headers[idempotency_header] = options.idempotency_key

# Don't set these headers if they were already set or removed by the caller. We check
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
Expand Down Expand Up @@ -944,6 +974,10 @@ def _request(
request = self._build_request(options, retries_taken=retries_taken)
self._prepare_request(request)

if options.idempotency_key:
# ensure the idempotency key is reused between requests
input_options.idempotency_key = options.idempotency_key

kwargs: HttpxSendArgs = {}
if self.custom_auth is not None:
kwargs["auth"] = self.custom_auth
Expand Down Expand Up @@ -1490,6 +1524,10 @@ async def _request(
request = self._build_request(options, retries_taken=retries_taken)
await self._prepare_request(request)

if options.idempotency_key:
# ensure the idempotency key is reused between requests
input_options.idempotency_key = options.idempotency_key

kwargs: HttpxSendArgs = {}
if self.custom_auth is not None:
kwargs["auth"] = self.custom_auth
Expand Down
1 change: 0 additions & 1 deletion src/lithic/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

import pydantic
import pydantic.generics
from pydantic.fields import FieldInfo

from ._types import (
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/_utils/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class MyResponse(Foo[_T]):
```
"""
cls = cast(object, get_origin(typ) or typ)
if cls in generic_bases:
if cls in generic_bases: # pyright: ignore[reportUnnecessaryContains]
# we're given the class directly
return extract_type_arg(typ, index)

Expand Down
Loading