LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmith_openapi_client_utils_syncasyncify
Function●Since v0.8

asyncify

Copy
asyncify(
  function: Callable[T_ParamSpec, T_Retval]
) -> Callable[T_ParamSpec, Awaitable
View source on GitHub
[
T_Retval
]
]

Take a blocking function and create an async one that receives the same positional and keyword arguments.

Usage:

def blocking_func(arg1, arg2, kwarg1=None):
    # blocking code
    return result

result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)

Arguments

function: a blocking regular callable (e.g. a function)

Return

An async function that takes the same positional and keyword arguments as the original one, that when called runs the same original function in a thread worker and returns the result.