mpu.io
Reading and writing common file formats.
- mpu.io.download(source: str, sink: Optional[str] = None) str [source]
Download a file.
- Parameters
source (str) – Where the file comes from. Some URL.
sink (str, optional (default: same filename in current directory)) – Where the file gets stored. Some filepath in the local file system.
- mpu.io.get_access_datetime(filepath: str) datetime.datetime [source]
Get the last time filepath was accessed.
- Parameters
filepath (str) –
- Returns
access_datetime
- Return type
datetime
- mpu.io.get_creation_datetime(filepath: str) Optional[datetime.datetime] [source]
Get the date that a file was created.
- Parameters
filepath (str) –
- Returns
creation_datetime
- Return type
Optional[datetime]
- mpu.io.get_file_meta(filepath: str) Dict[str, Any] [source]
Get meta-information about a file.
- Parameters
filepath (str) –
- Returns
meta
- Return type
dict
- mpu.io.get_modification_datetime(filepath: str) datetime.datetime [source]
Get the datetime that a file was last modified.
- Parameters
filepath (str) –
- Returns
modification_datetime
- Return type
datetime
- mpu.io.gzip_file(source: str, sink: str) None [source]
Create a GZIP file from a source file.
- Parameters
source (str) – Filepath
sink (str) – Filepath
- mpu.io.hash(filepath: str, method: Literal['sha1', 'md5'] = 'sha1', buffer_size: int = 65536) str [source]
Calculate a hash of a local file.
- Parameters
filepath (str) –
method ({'sha1', 'md5'}) –
buffer_size (int, optional (default: 65536 byte = 64 KiB)) – in byte
- Returns
hash
- Return type
str
- mpu.io.read(filepath: str, **kwargs: Any) Any [source]
Read a file.
Supported formats:
CSV
JSON, JSONL
pickle
- Parameters
filepath (str) – Path to the file that should be read. This methods action depends mainly on the file extension.
kwargs (Dict) – Any keywords for the specific file format. For CSV, this is ‘delimiter’, ‘quotechar’, ‘skiprows’, ‘format’
- Returns
data
- Return type
Union[str, bytes] or other (e.g. format=dicts)
- mpu.io.urlread(url: str, encoding: str = 'utf8') str [source]
Read the content of an URL.
- Parameters
url (str) –
encoding (str (default: "utf8")) –
- Returns
content
- Return type
str
- mpu.io.write(filepath: str, data: Union[Dict, List], **kwargs: Any) Any [source]
Write a file.
Supported formats:
CSV
JSON, JSONL
pickle
- Parameters
filepath (str) – Path to the file that should be read. This methods action depends mainly on the file extension. Make sure that it ends in .csv, .json, .jsonl, or .pickle.
data (Union[Dict, List]) – Content that should be written
kwargs (Dict) – Any keywords for the specific file format.
- Returns
data
- Return type
str or bytes