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 stytch/b2b/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import aiohttp
import jwt
import requests

from stytch.b2b.api.discovery import Discovery
from stytch.b2b.api.idp import IDP
Expand Down Expand Up @@ -47,6 +48,7 @@ def __init__(
environment: Optional[str] = None,
suppress_warnings: bool = False,
async_session: Optional[aiohttp.ClientSession] = None,
sync_session: Optional[requests.Session] = None,
fraud_environment: Optional[str] = None,
custom_base_url: Optional[str] = None,
):
Expand All @@ -56,6 +58,7 @@ def __init__(
environment=environment,
suppress_warnings=suppress_warnings,
async_session=async_session,
sync_session=sync_session,
fraud_environment=fraud_environment,
custom_base_url=custom_base_url,
)
Expand Down
3 changes: 3 additions & 0 deletions stytch/consumer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import aiohttp
import jwt
import requests

from stytch.consumer.api.connected_apps import ConnectedApp
from stytch.consumer.api.crypto_wallets import CryptoWallets
Expand Down Expand Up @@ -45,6 +46,7 @@ def __init__(
environment: Optional[str] = None,
suppress_warnings: bool = False,
async_session: Optional[aiohttp.ClientSession] = None,
sync_session: Optional[requests.Session] = None,
fraud_environment: Optional[str] = None,
custom_base_url: Optional[str] = None,
):
Expand All @@ -54,6 +56,7 @@ def __init__(
environment=environment,
suppress_warnings=suppress_warnings,
async_session=async_session,
sync_session=sync_session,
fraud_environment=fraud_environment,
custom_base_url=custom_base_url,
)
Expand Down
4 changes: 3 additions & 1 deletion stytch/core/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import aiohttp
import jwt
import requests

from stytch.core.api_base import ApiBase
from stytch.core.http.client import AsyncClient, SyncClient
Expand All @@ -17,6 +18,7 @@ def __init__(
environment: Optional[str] = None,
suppress_warnings: bool = False,
async_session: Optional[aiohttp.ClientSession] = None,
sync_session: Optional[requests.Session] = None,
fraud_environment: Optional[str] = None,
custom_base_url: Optional[str] = None,
):
Expand All @@ -29,7 +31,7 @@ def __init__(
fraud_base_url = fraud_environment
self.api_base = ApiBase(base_url)
self.fraud_api_base = ApiBase(fraud_base_url)
self.sync_client = SyncClient(project_id, secret)
self.sync_client = SyncClient(project_id, secret, session=sync_session)
self.async_client = AsyncClient(project_id, secret, session=async_session)
self.jwks_client = self.get_jwks_client(project_id)

Expand Down
15 changes: 14 additions & 1 deletion stytch/core/http/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@
import asyncio
import unittest

from stytch.core.http.client import AsyncClient
import requests

from stytch.core.http.client import AsyncClient, SyncClient


class NoEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
def get_event_loop(self):
raise RuntimeError("No event loop")


class TestSyncClient(unittest.TestCase):
def test_external_session_is_used(self):
session = requests.Session()
client = SyncClient("project_id", "secret", session=session)
self.assertIs(client._session, session)

def test_no_external_session_creates_one(self):
client = SyncClient("project_id", "secret")
self.assertIsInstance(client._session, requests.Session)


class TestAsyncClient(unittest.TestCase):
def test_session_without_event_loop(self):
asyncio.set_event_loop_policy(NoEventLoopPolicy())
Expand Down
2 changes: 1 addition & 1 deletion stytch/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "14.3.0"
__version__ = "14.4.0"
Loading