OpenAPILoader API Reference
langchain_openapi_tools.loader.OpenAPILoader
Loader for obtaining normalized OpenAPI specifications from various sources.
Supported sources include local JSON/YAML files, remote URLs, and in-memory dicts.
Source code in langchain_openapi_tools/loader.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
__init__(load_fn, source_info, source_url=None)
Initialize loader with a fetch callable and a source description string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
load_fn
|
Callable[[], dict[str, Any]]
|
A zero-argument callable that returns a raw spec dictionary. |
required |
source_info
|
str
|
Human-readable description of the source for logging. |
required |
source_url
|
str | None
|
Optional absolute URL the specification was fetched
from. Preserved on the resulting |
None
|
Source code in langchain_openapi_tools/loader.py
from_dict(spec_dict)
classmethod
Create an OpenAPILoader from an in-memory dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec_dict
|
dict[str, Any]
|
Raw Python dictionary containing the OpenAPI specification. |
required |
Returns:
| Type | Description |
|---|---|
OpenAPILoader
|
An OpenAPILoader instance configured for dictionary loading. |
Source code in langchain_openapi_tools/loader.py
from_file(file_path)
classmethod
Create an OpenAPILoader for a local JSON or YAML file source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to the local OpenAPI specification file. |
required |
Returns:
| Type | Description |
|---|---|
OpenAPILoader
|
An OpenAPILoader instance configured for file loading. |
Source code in langchain_openapi_tools/loader.py
from_url(url, timeout=30.0, headers=None)
classmethod
Create an OpenAPILoader for a remote URL source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP or HTTPS URL of the OpenAPI specification. |
required |
timeout
|
float
|
Request timeout in seconds (default: 30.0). |
30.0
|
headers
|
dict[str, str] | None
|
Optional dictionary of HTTP headers for the request. |
None
|
Returns:
| Type | Description |
|---|---|
OpenAPILoader
|
An OpenAPILoader instance configured for URL fetching. |
Source code in langchain_openapi_tools/loader.py
load()
Load, validate, and normalize the OpenAPI specification.
Returns:
| Type | Description |
|---|---|
OpenAPISpec
|
An OpenAPISpec instance containing the normalized specification data. |
Raises:
| Type | Description |
|---|---|
SpecLoadError
|
If loading from source or parsing JSON/YAML fails. |
InvalidSpecError
|
If required fields ('openapi', 'paths') are missing. |
UnsupportedVersionError
|
If the OpenAPI version is unsupported. |