kloppy.io
kloppy.io
I/O utilities for reading raw data.
Source
dataclass
A wrapper around a file-like object to enable optional inputs.
PARAMETER | DESCRIPTION |
---|---|
data
|
The file-like object.
TYPE:
|
optional
|
Whether the file is optional. Defaults to False.
TYPE:
|
skip_if_missing
|
Whether to skip the file if it is missing. Defaults to False.
TYPE:
|
Example:
1 |
|
open_as_file
Open a byte stream to the given input object.
The following input types are supported
- A string or
pathlib.Path
object representing a local file path. - A string representing a URL. It should start with 'http://' or 'https://'.
- A string representing a path to a file in a Amazon S3 cloud storage bucket. It should start with 's3://'.
- A xml or json string containing the data. The string should contain a '{' or '<' character. Otherwise, it will be treated as a file path.
- A bytes object containing the data.
- A buffered binary stream that inherits from
io.BufferedIOBase
. - A Source object that wraps any of the above input types.
PARAMETER | DESCRIPTION |
---|---|
input_
|
The input object to be opened.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BinaryIO
|
A binary stream to the input object.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input is required but not provided. |
InputNotFoundError
|
If the input file is not found and should not be skipped. |
TypeError
|
If the input type is not supported. |
Example:
1 2 |
|
Note
To support reading data from other sources, see the Adapter class.
If the given file path or URL ends with '.gz', '.xz', or '.bz2', the file will be decompressed before being read.
Source code in kloppy/io.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
get_file_extension
Determine the file extension of the given file-like object.
If the file has compression extensions such as '.gz', '.xz', or '.bz2', they will be stripped before determining the extension.
PARAMETER | DESCRIPTION |
---|---|
file_or_path
|
The file-like object whose extension needs to be determined.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The file extension, including the dot ('.') if present.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
Exception
|
If the extension cannot be determined. |
Example:
1 2 3 4 5 6 |
|