Skip to main content

Web-ready standardized file processing and serialization. Read, load and convert to standard file types with a common interface.

Project description

Mutimodal-files

Web-ready standardized file processing and serialization

Features

Read, load and convert to standard file types with a common interface. Especially useful for code that works with multiple file types like images, audio, video, etc.

Load and convert from and to common data types:

  • numpy arrays
  • file paths
  • bytes,
  • base64
  • json
  • etc.

Transmit files between services with a common interface

  • Native FastSDK and FastTaskAPI integration
  • Supports httpx, requests

Work with native python libs like BytesIO.

Only use the file types you need, no unnecessary dependencies.

Installation

You can install the package with PIP, or clone the repository.

# install full version
pip install multimodal-files[full]
# install from pypi (no dependencies)
pip install multimodal-files

# install from github for newest release
pip install git+git://github.com/SocAIty/multimodal-files

The version without dependencies does not include the optional dependencies like numpy, soundfile, etc. Instead you can only install the dependencies which are required for your project. Making the package size tiny.

Usage

Create a multimodal-file from any data type

The library automatically detect the data type and loads it correctly.

from multimodal_files import MultiModalFile, ImageFile, AudioFile, VideoFile

# represents either path, base64, bytesio, file_handle, numpy array ...
arbitrary_data = "...."
new_file = ImageFile().from_any(arbitrary_data)

All files (ImageFile, AudioFile, VideoFile) types support the same interface / methods.

Explicitly load from a certain type.

This method is more secure than from_any, because it definitely uses the correct method to load the file.

new_file = MultiModalFile()

new_file.from_file("path/to/file")
new_file.from_file(open("path/to/file", "rb"))
new_file.from_numpy_array(my_array)
new_file.from_bytes(b'bytes')
new_file.from_base64('base64string')
new_file.from_starlette_upload_file(starlette_upload_file)

Convert to any format or write to file

Supports common serialization methods like bytes(), np.array(), dict()

my_file = ImageFile().from_file("path/to/my_image.png")

my_file.save("path/to/new_file.png")  
as_numpy_array = my_file.to_numpy_array()
as_numpy_array = np.array(my_file)

as_bytes = my_file.to_bytes()
as_bytes = bytes(my_file)
as_base64 = my_file.to_base64()
as_json = my_file.to_json()

Easy conversion from any type

my_image_file = convert_to_upload_file_type(arbitrary_data, ImageFile) 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multimodal_files-0.0.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

multimodal_files-0.0.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file multimodal_files-0.0.0.tar.gz.

File metadata

  • Download URL: multimodal_files-0.0.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for multimodal_files-0.0.0.tar.gz
Algorithm Hash digest
SHA256 80e87952563ec5cc735b16626022efb1afa38895a67b1c41a2be2f198e65df28
MD5 34015ff69560590500a24431a8e43546
BLAKE2b-256 79412d8c1218a1e414725d3b0f49819d7b68313ae07bd6f66fe5c0a2c7b16cc2

See more details on using hashes here.

File details

Details for the file multimodal_files-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for multimodal_files-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1332bb8d2c84c96098b123244448cb398e2339d8afda3d18a2f8509e60753784
MD5 a098b6679694248d04ad7423c5619830
BLAKE2b-256 960e69cc9ad07899529027d21f5a6c9f2f41f857dfd01057ef74e9b4f952c807

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page