_parse_data_uri() — langchain Function Reference
Architecture documentation for the _parse_data_uri() function in _utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 93c33ec3_5899_b584_ba79_8d4acbe0e72f["_parse_data_uri()"] 52504dd3_f4d4_21a4_b28c_0c152227d20d["_utils.py"] 93c33ec3_5899_b584_ba79_8d4acbe0e72f -->|defined in| 52504dd3_f4d4_21a4_b28c_0c152227d20d style 93c33ec3_5899_b584_ba79_8d4acbe0e72f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/language_models/_utils.py lines 89–121
def _parse_data_uri(uri: str) -> ParsedDataUri | None:
"""Parse a data URI into its components.
If parsing fails, return `None`. If either MIME type or data is missing, return
`None`.
Example:
```python
data_uri = "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
parsed = _parse_data_uri(data_uri)
assert parsed == {
"source_type": "base64",
"mime_type": "image/jpeg",
"data": "/9j/4AAQSkZJRg...",
}
```
"""
regex = r"^data:(?P<mime_type>[^;]+);base64,(?P<data>.+)$"
match = re.match(regex, uri)
if match is None:
return None
mime_type = match.group("mime_type")
data = match.group("data")
if not mime_type or not data:
return None
return {
"source_type": "base64",
"data": data,
"mime_type": mime_type,
}
Domain
Subdomains
Source
Frequently Asked Questions
What does _parse_data_uri() do?
_parse_data_uri() is a function in the langchain codebase, defined in libs/core/langchain_core/language_models/_utils.py.
Where is _parse_data_uri() defined?
_parse_data_uri() is defined in libs/core/langchain_core/language_models/_utils.py at line 89.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free