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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/__pycache__/
**/.speakeasy/temp/
**/.speakeasy/logs/
.speakeasy/reports
Expand Down
30 changes: 15 additions & 15 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ generation:
oAuth2ClientCredentialsEnabled: true
oAuth2PasswordEnabled: false
python:
version: 2.1.0
version: 2.2.0
additionalDependencies:
dev:
pytest: ^8.3.3
Expand Down
10 changes: 5 additions & 5 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
speakeasyVersion: 1.542.3
speakeasyVersion: 1.544.0
sources:
clerk-openapi:
sourceNamespace: clerk-openapi
sourceRevisionDigest: sha256:b04b66d6cf242e4b34536e792b8cf9fe2241bf8c772d48a5c332cfbd2450cf30
sourceRevisionDigest: sha256:de9c2e88aec282e2babce91d125306ce397fd12d4cb85f9d12f9cd7cdba60f69
sourceBlobDigest: sha256:d64d439a324819076eb2941bddebe10c544f5d276cd95788970d49c8f643bcf1
tags:
- latest
- speakeasy-sdk-regen-1744935656
- speakeasy-sdk-regen-1747144886
- "2024-10-01"
targets:
clerk-sdk-python:
source: clerk-openapi
sourceNamespace: clerk-openapi
sourceRevisionDigest: sha256:b04b66d6cf242e4b34536e792b8cf9fe2241bf8c772d48a5c332cfbd2450cf30
sourceRevisionDigest: sha256:de9c2e88aec282e2babce91d125306ce397fd12d4cb85f9d12f9cd7cdba60f69
sourceBlobDigest: sha256:d64d439a324819076eb2941bddebe10c544f5d276cd95788970d49c8f643bcf1
codeSamplesNamespace: clerk-openapi-python-code-samples
codeSamplesRevisionDigest: sha256:b0fbbc5d5ff733c77b578b8859510557fdb669a43976e256d33bd32732cf1e15
codeSamplesRevisionDigest: sha256:ea80d8442e2d861fe6e5910b6a862b325e94fc1058dd73aee41eb2007a1a525f
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,14 @@ Based on:
### Generated
- [python v2.1.0] .
### Releases
- [PyPI v2.1.0] https://pypi.org/project/clerk-backend-api/2.1.0 - .
- [PyPI v2.1.0] https://pypi.org/project/clerk-backend-api/2.1.0 - .

## 2025-05-13 14:01:09
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.544.0 (2.599.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v2.2.0] .
### Releases
- [PyPI v2.2.0] https://pypi.org/project/clerk-backend-api/2.2.0 - .
84 changes: 47 additions & 37 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "clerk-backend-api"
version = "2.1.0"
version = "2.2.0"
description = "Python Client SDK for clerk.dev"
authors = [{ name = "Clerk" },]
readme = "README.md"
requires-python = ">=3.9"
readme = "README-PYPI.md"
requires-python = ">=3.9.2"
dependencies = [
"cryptography (>=43.0.1,<44.0.0)",
"cryptography (>=44.0.1,<45.0.0)",
"httpx >=0.28.1",
"pydantic >=2.11.2",
"pyjwt (>=2.9.0,<3.0.0)",
Expand Down
6 changes: 3 additions & 3 deletions src/clerk_backend_api/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import importlib.metadata

__title__: str = "clerk-backend-api"
__version__: str = "2.1.0"
__version__: str = "2.2.0"
__openapi_doc_version__: str = "2024-10-01"
__gen_version__: str = "2.597.9"
__user_agent__: str = "speakeasy-sdk/python 2.1.0 2.597.9 2024-10-01 clerk-backend-api"
__gen_version__: str = "2.599.0"
__user_agent__: str = "speakeasy-sdk/python 2.2.0 2.599.0 2024-10-01 clerk-backend-api"

try:
if __package__ is not None:
Expand Down
50 changes: 35 additions & 15 deletions src/clerk_backend_api/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# pyright: reportReturnType = false
import asyncio
from concurrent.futures import ThreadPoolExecutor
from typing_extensions import Protocol, runtime_checkable
import httpx
from typing import Any, Optional, Union
Expand Down Expand Up @@ -116,21 +115,42 @@ def close_clients(
pass

if async_client is not None and not async_client_supplied:
is_async = False
# First, try the simplest approach - use asyncio.run()
# This works when we're not in an async context
try:
asyncio.get_running_loop()
is_async = True
except RuntimeError:
pass

try:
# If this function is called in an async loop then start another
# loop in a separate thread to close the async http client.
if is_async:
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(asyncio.run, async_client.aclose())
future.result()
asyncio.run(async_client.aclose())
except RuntimeError as e:
# If we get "RuntimeError: This event loop is already running",
# it means we're in an async context
if "already running" in str(e):
try:
# We're in an async context, so get the running loop
loop = asyncio.get_running_loop()
# Create a task but don't wait for it
loop.create_task(async_client.aclose())
except Exception:
# If we can't get the loop or create a task, just ignore
# The GC will eventually clean up the resources
pass
# If we get "RuntimeError: There is no current event loop in thread",
# we're not in an async context, but asyncio.run() failed for some reason
# In this case, we can try to create a new event loop explicitly
elif "no current event loop" in str(e):
try:
# Create a new event loop and run the coroutine
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(async_client.aclose())
finally:
loop.close()
asyncio.set_event_loop(None)
except Exception:
# If this also fails, just ignore
pass
# For any other RuntimeError, just ignore
else:
asyncio.run(async_client.aclose())
pass
except Exception:
# For any other exception, just ignore
pass