| [ Web Proxy ] |
| Viewing: https://docs.docarray.org/API_reference/array/../../../../../API_reference/typing/url/ | [Back] [Original] |
docarray.typing.url
AnyUrl
Bases: AnyUrl, AbstractType
docarray/typing/url/any_url.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
extra_extensions()
classmethod
Returns a list of allowed file extensions for the class that are not covered by the mimetypes library.
Source code indocarray/typing/url/any_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
mime_type()
classmethod
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
AudioUrl
Bases: AnyUrl
URL to an audio file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/audio_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Play the audio sound from url in notebook.
Source code indocarray/typing/url/audio_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/audio_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load()
Load the data from the url into an AudioNdArray
and the frame rate.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioNdArray, AudioUrl
class MyDoc(BaseDoc):
audio_url: AudioUrl
audio_tensor: Optional[AudioNdArray] = None
doc = MyDoc(audio_url='https://www.kozco.com/tech/piano2.wav')
doc.audio_tensor, _ = doc.audio_url.load()
assert isinstance(doc.audio_tensor, AudioNdArray)
Returns:
| Type | Description |
|---|---|
Tuple[AudioNdArray, int]
|
tuple of an |
docarray/typing/url/audio_url.py
load_bytes(timeout=None)
Convert url to AudioBytes. This will either load or
download the file and save it into an AudioBytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
| Type | Description |
|---|---|
AudioBytes
|
|
docarray/typing/url/audio_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
ImageUrl
Bases: AnyUrl
URL to an image file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/image_url.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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Display image data from url in notebook.
Source code indocarray/typing/url/image_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/image_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(width=None, height=None, axis_layout=('H', 'W', 'C'), timeout=None)
Load the data from the url into an ImageNdArray
from docarray import BaseDoc
from docarray.typing import ImageUrl, ImageNdArray
class MyDoc(BaseDoc):
img_url: ImageUrl
doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, ImageNdArray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width |
Optional[int]
|
width of the image tensor. |
None
|
height |
Optional[int]
|
height of the image tensor. |
None
|
axis_layout |
Tuple[str, str, str]
|
ordering of the different image axes. 'H' = height, 'W' = width, 'C' = color channel |
('H', 'W', 'C')
|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
Returns:
| Type | Description |
|---|---|
ImageNdArray
|
|
docarray/typing/url/image_url.py
load_bytes(timeout=None)
Convert url to ImageBytes. This will either load or
download the file and save it into an ImageBytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
| Type | Description |
|---|---|
ImageBytes
|
|
docarray/typing/url/image_url.py
load_pil(timeout=None)
Load the image from the bytes into a PIL.Image.Image instance
from pydantic import parse_obj_as
from docarray import BaseDoc
from docarray.typing import ImageUrl
img_url = "https://upload.wikimedia.org/wikipedia/commons/8/80/Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
img_url = parse_obj_as(ImageUrl, img_url)
img = img_url.load_pil()
from PIL.Image import Image
assert isinstance(img, Image)
Returns:
| Type | Description |
|---|---|
Image
|
a Pillow image |
docarray/typing/url/image_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
Mesh3DUrl
Bases: Url3D
URL to a file containing 3D mesh information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/mesh_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Plot mesh from url. This loads the Trimesh instance of the 3D mesh, and then displays it.
Source code indocarray/typing/url/url_3d/mesh_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/url_3d/mesh_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(skip_materials=True, trimesh_args=None)
Load the data from the url into a VerticesAndFaces
object containing vertices and faces information.
from docarray import BaseDoc
from docarray.typing import Mesh3DUrl, NdArray
class MyDoc(BaseDoc):
mesh_url: Mesh3DUrl
doc = MyDoc(mesh_url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
tensors = doc.mesh_url.load()
assert isinstance(tensors.vertices, NdArray)
assert isinstance(tensors.faces, NdArray)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_materials |
bool
|
Skip materials if True, else skip. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
| Type | Description |
|---|---|
VerticesAndFaces
|
VerticesAndFaces object containing vertices and faces information. |
docarray/typing/url/url_3d/mesh_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
PointCloud3DUrl
Bases: Url3D
URL to a file containing point cloud information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/point_cloud_url.py
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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display(samples=10000)
Plot point cloud from url.
First, it loads the point cloud into a PointsAndColors object, and then
calls display on it. The following is therefore equivalent:
import numpy as np
from docarray import BaseDoc
from docarray.documents import PointCloud3D
pc = PointCloud3D(url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# option 1
# pc.url.display()
# option 2 (equivalent)
# pc.url.load(samples=10000).display()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples |
int
|
number of points to sample from the mesh. |
10000
|
docarray/typing/url/url_3d/point_cloud_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/url_3d/point_cloud_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(samples, multiple_geometries=False, skip_materials=True, trimesh_args=None)
Load the data from the url into an NdArray containing point cloud information.
import numpy as np
from docarray import BaseDoc
from docarray.typing import PointCloud3DUrl
class MyDoc(BaseDoc):
point_cloud_url: PointCloud3DUrl
doc = MyDoc(point_cloud_url="thttps://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# point_cloud = doc.point_cloud_url.load(samples=100)
# assert isinstance(point_cloud, np.ndarray)
# assert point_cloud.shape == (100, 3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples |
int
|
number of points to sample from the mesh |
required |
multiple_geometries |
bool
|
if False, store point cloud in 2D np.ndarray. If True, store point clouds from multiple geometries in 3D np.ndarray. |
False
|
skip_materials |
bool
|
Skip materials if True, else load. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
| Type | Description |
|---|---|
PointsAndColors
|
np.ndarray representing the point cloud |
docarray/typing/url/url_3d/point_cloud_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
TextUrl
Bases: AnyUrl
URL to a text file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/text_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/text_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(charset='utf-8', timeout=None)
Load the text file into a string.
from docarray import BaseDoc
from docarray.typing import TextUrl
class MyDoc(BaseDoc):
remote_url: TextUrl
doc = MyDoc(
remote_url='https://de.wikipedia.org/wiki/Brixen',
)
remote_txt = doc.remote_url.load()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
charset |
str
|
decoding charset; may be any character set registered with IANA |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
the text file content |
docarray/typing/url/text_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
VideoUrl
Bases: AnyUrl
URL to a video file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/video_url.py
13 14 15 16 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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Play video from url in notebook.
Source code indocarray/typing/url/video_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/video_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(**kwargs)
Load the data from the url into a NamedTuple of
VideoNdArray,
AudioNdArray
and NdArray.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import VideoUrl, VideoNdArray, AudioNdArray, NdArray
class MyDoc(BaseDoc):
video_url: VideoUrl
video: Optional[VideoNdArray] = None
audio: Optional[AudioNdArray] = None
key_frame_indices: Optional[NdArray] = None
doc = MyDoc(
video_url='https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true'
)
doc.video, doc.audio, doc.key_frame_indices = doc.video_url.load()
assert isinstance(doc.video, VideoNdArray)
assert isinstance(doc.audio, AudioNdArray)
assert isinstance(doc.key_frame_indices, NdArray)
You can load only the key frames (or video, audio respectively):
from pydantic import parse_obj_as
from docarray.typing import NdArray, VideoUrl
url = parse_obj_as(
VideoUrl,
'https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true',
)
key_frame_indices = url.load().key_frame_indices
assert isinstance(key_frame_indices, NdArray)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs |
supports all keyword arguments that are being supported by av.open() as described here |
{}
|
Returns:
| Type | Description |
|---|---|
VideoLoadResult
|
|
docarray/typing/url/video_url.py
load_bytes(timeout=None)
Convert url to VideoBytes. This will either load or download
the file and save it into an VideoBytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
| Type | Description |
|---|---|
VideoBytes
|
|
docarray/typing/url/video_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
any_url
AnyUrl
Bases: AnyUrl, AbstractType
docarray/typing/url/any_url.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
extra_extensions()
classmethod
Returns a list of allowed file extensions for the class that are not covered by the mimetypes library.
Source code indocarray/typing/url/any_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
mime_type()
classmethod
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
audio_url
AudioUrl
Bases: AnyUrl
URL to an audio file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/audio_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Play the audio sound from url in notebook.
Source code indocarray/typing/url/audio_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/audio_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load()
Load the data from the url into an AudioNdArray
and the frame rate.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioNdArray, AudioUrl
class MyDoc(BaseDoc):
audio_url: AudioUrl
audio_tensor: Optional[AudioNdArray] = None
doc = MyDoc(audio_url='https://www.kozco.com/tech/piano2.wav')
doc.audio_tensor, _ = doc.audio_url.load()
assert isinstance(doc.audio_tensor, AudioNdArray)
Returns:
| Type | Description |
|---|---|
Tuple[AudioNdArray, int]
|
tuple of an |
docarray/typing/url/audio_url.py
load_bytes(timeout=None)
Convert url to AudioBytes. This will either load or
download the file and save it into an AudioBytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
| Type | Description |
|---|---|
AudioBytes
|
|
docarray/typing/url/audio_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
image_url
ImageUrl
Bases: AnyUrl
URL to an image file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/image_url.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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Display image data from url in notebook.
Source code indocarray/typing/url/image_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/image_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(width=None, height=None, axis_layout=('H', 'W', 'C'), timeout=None)
Load the data from the url into an ImageNdArray
from docarray import BaseDoc
from docarray.typing import ImageUrl, ImageNdArray
class MyDoc(BaseDoc):
img_url: ImageUrl
doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, ImageNdArray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width |
Optional[int]
|
width of the image tensor. |
None
|
height |
Optional[int]
|
height of the image tensor. |
None
|
axis_layout |
Tuple[str, str, str]
|
ordering of the different image axes. 'H' = height, 'W' = width, 'C' = color channel |
('H', 'W', 'C')
|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
Returns:
| Type | Description |
|---|---|
ImageNdArray
|
|
docarray/typing/url/image_url.py
load_bytes(timeout=None)
Convert url to ImageBytes. This will either load or
download the file and save it into an ImageBytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
| Type | Description |
|---|---|
ImageBytes
|
|
docarray/typing/url/image_url.py
load_pil(timeout=None)
Load the image from the bytes into a PIL.Image.Image instance
from pydantic import parse_obj_as
from docarray import BaseDoc
from docarray.typing import ImageUrl
img_url = "https://upload.wikimedia.org/wikipedia/commons/8/80/Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
img_url = parse_obj_as(ImageUrl, img_url)
img = img_url.load_pil()
from PIL.Image import Image
assert isinstance(img, Image)
Returns:
| Type | Description |
|---|---|
Image
|
a Pillow image |
docarray/typing/url/image_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
text_url
TextUrl
Bases: AnyUrl
URL to a text file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/text_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/text_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(charset='utf-8', timeout=None)
Load the text file into a string.
from docarray import BaseDoc
from docarray.typing import TextUrl
class MyDoc(BaseDoc):
remote_url: TextUrl
doc = MyDoc(
remote_url='https://de.wikipedia.org/wiki/Brixen',
)
remote_txt = doc.remote_url.load()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout (sec) for urlopen network request. Only relevant if URL is not local |
None
|
charset |
str
|
decoding charset; may be any character set registered with IANA |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
str
|
the text file content |
docarray/typing/url/text_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
url_3d
Mesh3DUrl
Bases: Url3D
URL to a file containing 3D mesh information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/mesh_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Plot mesh from url. This loads the Trimesh instance of the 3D mesh, and then displays it.
Source code indocarray/typing/url/url_3d/mesh_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/url_3d/mesh_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(skip_materials=True, trimesh_args=None)
Load the data from the url into a VerticesAndFaces
object containing vertices and faces information.
from docarray import BaseDoc
from docarray.typing import Mesh3DUrl, NdArray
class MyDoc(BaseDoc):
mesh_url: Mesh3DUrl
doc = MyDoc(mesh_url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
tensors = doc.mesh_url.load()
assert isinstance(tensors.vertices, NdArray)
assert isinstance(tensors.faces, NdArray)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_materials |
bool
|
Skip materials if True, else skip. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
| Type | Description |
|---|---|
VerticesAndFaces
|
VerticesAndFaces object containing vertices and faces information. |
docarray/typing/url/url_3d/mesh_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
PointCloud3DUrl
Bases: Url3D
URL to a file containing point cloud information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/point_cloud_url.py
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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display(samples=10000)
Plot point cloud from url.
First, it loads the point cloud into a PointsAndColors object, and then
calls display on it. The following is therefore equivalent:
import numpy as np
from docarray import BaseDoc
from docarray.documents import PointCloud3D
pc = PointCloud3D(url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# option 1
# pc.url.display()
# option 2 (equivalent)
# pc.url.load(samples=10000).display()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples |
int
|
number of points to sample from the mesh. |
10000
|
docarray/typing/url/url_3d/point_cloud_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/url_3d/point_cloud_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(samples, multiple_geometries=False, skip_materials=True, trimesh_args=None)
Load the data from the url into an NdArray containing point cloud information.
import numpy as np
from docarray import BaseDoc
from docarray.typing import PointCloud3DUrl
class MyDoc(BaseDoc):
point_cloud_url: PointCloud3DUrl
doc = MyDoc(point_cloud_url="thttps://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# point_cloud = doc.point_cloud_url.load(samples=100)
# assert isinstance(point_cloud, np.ndarray)
# assert point_cloud.shape == (100, 3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples |
int
|
number of points to sample from the mesh |
required |
multiple_geometries |
bool
|
if False, store point cloud in 2D np.ndarray. If True, store point clouds from multiple geometries in 3D np.ndarray. |
False
|
skip_materials |
bool
|
Skip materials if True, else load. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
| Type | Description |
|---|---|
PointsAndColors
|
np.ndarray representing the point cloud |
docarray/typing/url/url_3d/point_cloud_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
mesh_url
Mesh3DUrl
Bases: Url3D
URL to a file containing 3D mesh information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/mesh_url.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Plot mesh from url. This loads the Trimesh instance of the 3D mesh, and then displays it.
Source code indocarray/typing/url/url_3d/mesh_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/url_3d/mesh_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(skip_materials=True, trimesh_args=None)
Load the data from the url into a VerticesAndFaces
object containing vertices and faces information.
from docarray import BaseDoc
from docarray.typing import Mesh3DUrl, NdArray
class MyDoc(BaseDoc):
mesh_url: Mesh3DUrl
doc = MyDoc(mesh_url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
tensors = doc.mesh_url.load()
assert isinstance(tensors.vertices, NdArray)
assert isinstance(tensors.faces, NdArray)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_materials |
bool
|
Skip materials if True, else skip. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
| Type | Description |
|---|---|
VerticesAndFaces
|
VerticesAndFaces object containing vertices and faces information. |
docarray/typing/url/url_3d/mesh_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
point_cloud_url
PointCloud3DUrl
Bases: Url3D
URL to a file containing point cloud information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/point_cloud_url.py
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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display(samples=10000)
Plot point cloud from url.
First, it loads the point cloud into a PointsAndColors object, and then
calls display on it. The following is therefore equivalent:
import numpy as np
from docarray import BaseDoc
from docarray.documents import PointCloud3D
pc = PointCloud3D(url="https://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# option 1
# pc.url.display()
# option 2 (equivalent)
# pc.url.load(samples=10000).display()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples |
int
|
number of points to sample from the mesh. |
10000
|
docarray/typing/url/url_3d/point_cloud_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/url_3d/point_cloud_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(samples, multiple_geometries=False, skip_materials=True, trimesh_args=None)
Load the data from the url into an NdArray containing point cloud information.
import numpy as np
from docarray import BaseDoc
from docarray.typing import PointCloud3DUrl
class MyDoc(BaseDoc):
point_cloud_url: PointCloud3DUrl
doc = MyDoc(point_cloud_url="thttps://people.sc.fsu.edu/~jburkardt/data/obj/al.obj")
# point_cloud = doc.point_cloud_url.load(samples=100)
# assert isinstance(point_cloud, np.ndarray)
# assert point_cloud.shape == (100, 3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples |
int
|
number of points to sample from the mesh |
required |
multiple_geometries |
bool
|
if False, store point cloud in 2D np.ndarray. If True, store point clouds from multiple geometries in 3D np.ndarray. |
False
|
skip_materials |
bool
|
Skip materials if True, else load. |
True
|
trimesh_args |
Optional[Dict[str, Any]]
|
dictionary of additional arguments for |
None
|
Returns:
| Type | Description |
|---|---|
PointsAndColors
|
np.ndarray representing the point cloud |
docarray/typing/url/url_3d/point_cloud_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
url_3d
Url3D
Bases: AnyUrl, ABC
URL to a file containing 3D mesh or point cloud information. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/url_3d/url_3d.py
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
extra_extensions()
classmethod
Returns a list of allowed file extensions for the class that are not covered by the mimetypes library.
Source code indocarray/typing/url/any_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load_bytes(timeout=None)
Convert url to bytes. This will either load or download the file and save it into a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if URI is not local |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
bytes. |
docarray/typing/url/any_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
video_url
VideoUrl
Bases: AnyUrl
URL to a video file. Can be remote (web) URL, or a local file path.
Source code indocarray/typing/url/video_url.py
13 14 15 16 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 | |
build(*, scheme, user=None, password=None, host, port=None, path=None, query=None, fragment=None, **_kwargs)
classmethod
Build a URL from its parts.
The only difference from the pydantic implementation is that we allow
missing scheme, making it possible to pass a file path without prefix.
docarray/typing/url/any_url.py
display()
Play video from url in notebook.
Source code indocarray/typing/url/video_url.py
extra_extensions()
classmethod
Returns a list of additional file extensions that are valid for this class but cannot be identified by the mimetypes library.
Source code indocarray/typing/url/video_url.py
from_protobuf(pb_msg)
classmethod
Read url from a proto msg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb_msg |
str
|
|
required |
Returns:
| Type | Description |
|---|---|
T
|
url |
docarray/typing/url/any_url.py
is_extension_allowed(value)
classmethod
Check if the file extension of the URL is allowed for this class. First, it guesses the mime type of the file. If it fails to detect the mime type, it then checks the extra file extensions. Note: This method assumes that any URL without an extension is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
Any
|
The URL or file path. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the extension is allowed, False otherwise |
docarray/typing/url/any_url.py
load(**kwargs)
Load the data from the url into a NamedTuple of
VideoNdArray,
AudioNdArray
and NdArray.
from typing import Optional
from docarray import BaseDoc
from docarray.typing import VideoUrl, VideoNdArray, AudioNdArray, NdArray
class MyDoc(BaseDoc):
video_url: VideoUrl
video: Optional[VideoNdArray] = None
audio: Optional[AudioNdArray] = None
key_frame_indices: Optional[NdArray] = None
doc = MyDoc(
video_url='https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true'
)
doc.video, doc.audio, doc.key_frame_indices = doc.video_url.load()
assert isinstance(doc.video, VideoNdArray)
assert isinstance(doc.audio, AudioNdArray)
assert isinstance(doc.key_frame_indices, NdArray)
You can load only the key frames (or video, audio respectively):
from pydantic import parse_obj_as
from docarray.typing import NdArray, VideoUrl
url = parse_obj_as(
VideoUrl,
'https://github.com/docarray/docarray/blob/main/tests/toydata/mov_bbb.mp4?raw=true',
)
key_frame_indices = url.load().key_frame_indices
assert isinstance(key_frame_indices, NdArray)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs |
supports all keyword arguments that are being supported by av.open() as described here |
{}
|
Returns:
| Type | Description |
|---|---|
VideoLoadResult
|
|
docarray/typing/url/video_url.py
load_bytes(timeout=None)
Convert url to VideoBytes. This will either load or download
the file and save it into an VideoBytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
Optional[float]
|
timeout for urlopen. Only relevant if url is not local |
None
|
Returns:
| Type | Description |
|---|---|
VideoBytes
|
|
docarray/typing/url/video_url.py
validate_parts(parts, validate_port=True)
classmethod
A method used to validate parts of a URL.
Our URLs should be able to function both in local and remote settings.
Therefore, we allow missing scheme, making it possible to pass a file
path without prefix.
If scheme is missing, we assume it is a local file path.
docarray/typing/url/any_url.py
| Web Proxy Viewer | New URL | Original Page |