Skip to main content

A wrapper for in-memory bytes with mime types, providing conversion between local files (support hardlinks and symlinks), base64 and data urls.

Project description

MimeBytes

Installation

pip install mime-bytes-py

Usage

from mime_bytes import MimeBytes

this_script: MimeBytes = MimeBytes.from_file(__file__)
print(this_script)  # <MimeBytes text/x-python (... bytes)>
print(this_script.to_base64())  # ZnJvbSBtaW1lX2J5dGVzIGltcG9ydCBNaW1lQnl0ZXMNC...
print(this_script.to_file("hardlink", guess_suffix=True, link_mode="hardlink_only"))  # ...\hardlink.py
from mime_bytes import MimeBytes
import openai

image: MimeBytes = MimeBytes.from_file("my_image.png")
openai.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user", 
            "content": [
                { "type": "image_url", "image_url": { "url": image.to_data_url() } },
                { "type": "text", "text": "Please describe the image." }
            ]
        }
    ]
)

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

mime_bytes_py-0.1.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mime_bytes_py-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file mime_bytes_py-0.1.1.tar.gz.

File metadata

  • Download URL: mime_bytes_py-0.1.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mime_bytes_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 148fcf411bf37603f203f41ddead60c60bc6ed212bcc6454ba0127c7d1f864e8
MD5 3e43568e24b49983ba48ec4796978b02
BLAKE2b-256 177da7ab8929bf1f392c507731300834d45cbb99fe0d65d56963ade5b4d074df

See more details on using hashes here.

File details

Details for the file mime_bytes_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mime_bytes_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mime_bytes_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1eb93237803402d08fa1b5b3b5b0174cf4d2d643d5884b23464a2b7b0a658f15
MD5 c6a965084700f851463b895386c5c867
BLAKE2b-256 52939e303e9b886c1d5d743e6c3c775e2727f7ffca166505c34501bc2ae11569

See more details on using hashes here.

Supported by

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