apyfal.storage

Data storage I/O

Support I/O over different kind of storage that must be first mounted.

Theses features are provided by the “pycosio”. Path are automatically handled with pycosio in Apyfal to provides automatic support of cloud storage.

Mount storage:
Storage defined in configuration are automatically mounted on first call. It is possible to manually mount new storage with “mount” function.

The Apyfal configuration file is used to automatically mount all known storage on start up.

Storage URL format:

All operations works with URL with format “scheme://path”

Common schemes are (mounted by default):

  • file://” or no scheme: Client local file.
  • “host://”: Host local file (Available only on REST client).
  • http://” or “https://”: File access over HTTP.

Some storage use advanced same, basic form is “StorageType://path” with StorageType the storage type defining this storage.

See target storage class documentation for more information.

apyfal.storage.copy(source, destination)[source]

Copy a file from source to destination.

Parameters:
  • source (path-like object or file-like object) – Source URL. Can be apyfal.storage URL, paths, file-like object.
  • destination (path-like object or file-like object) – Destination URL. Can be apyfal.storage URL, paths, file-like object.
apyfal.storage.mount(storage_type, **kwargs)[source]

Mount a new storage.

Parameters:
  • storage_type (str) – storage type
  • kwargs – Storage keywords argument (see targeted storage class for more information)
apyfal.storage.open(url, mode='rb', encoding=None, errors=None, newline=None)[source]

Open file and return a corresponding file object.

Parameters:
  • url (path-like object or file-like object) – URL or file object to open.
  • mode (str) – Mode in which the file is opened (Works like standard library open mode). Support at least ‘r’ (read), ‘w’ (write), ‘b’ (binary), ‘t’ (text) modes, eventually more depending on source file.
  • encoding (str) – with text mode, encoding used to decode or encode the file.
  • errors (str) – with text mode, specifies how encoding and decoding errors are to be handled
  • newline (str) – Controls how universal newlines mode works.
Returns:

Opened object handle

Return type:

file-like object

apyfal.storage.parse_url(url, host=True)[source]

Return storage_type and path from URL.

If URL has no scheme, “file” scheme is inferred.

If URL is a file-like object, returns “stream” as storage_type.

Parameters:
  • url (path-like object or file-like object) – URL to parse
  • host (bool) – If True, Scheme is returned from host point of view: “host” scheme is converted to “file” scheme.
Returns:

(storage_type, path)

Return type:

tuple of str