mpu.io¶
Reading and writing common file formats.
-
mpu.io.
download
(source: str, sink=None)[source]¶ Download a file.
- Parameters
source (str) – Where the file comes from. Some URL.
sink (str or None (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)[source]¶ Get the last time filepath was accessed.
- Parameters
filepath (str) –
- Returns
access_datetime
- Return type
datetime.datetime
-
mpu.io.
get_creation_datetime
(filepath: str)[source]¶ Get the date that a file was created.
- Parameters
filepath (str) –
- Returns
creation_datetime
- Return type
datetime.datetime or None
-
mpu.io.
get_file_meta
(filepath: str)[source]¶ Get meta-information about a file.
- Parameters
filepath (str) –
- Returns
meta
- Return type
dict
-
mpu.io.
get_modification_datetime
(filepath: str)[source]¶ Get the datetime that a file was last modified.
- Parameters
filepath (str) –
- Returns
modification_datetime
- Return type
datetime.datetime
-
mpu.io.
gzip_file
(source: str, sink: str)[source]¶ Create a GZIP file from a source file.
- Parameters
source (str) – Filepath
sink (str) – Filepath
-
mpu.io.
hash
(filepath: str, method='sha1', buffer_size=65536)[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)[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='utf8')[source]¶ Read the content of an URL.
- Parameters
url (str) –
- Returns
content
- Return type
str
-
mpu.io.
write
(filepath: str, data, **kwargs)[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.
data (dict or list) – Content that should be written
kwargs (dict) – Any keywords for the specific file format.
- Returns
data
- Return type
str or bytes