safetensors (0.7.0)

Published 2026-02-24 14:13:06 +00:00 by atheaadmin

Installation

pip install --index-url  safetensors

About this package

Installation

pip install safetensors

Usage

Numpy

from safetensors.numpy import save_file, load_file
import numpy as np

tensors = {
   "a": np.zeros((2, 2)),
   "b": np.zeros((2, 3), dtype=np.uint8)
}

save_file(tensors, "./model.safetensors")


# Now loading
loaded = load_file("./model.safetensors")

Torch

from safetensors.torch import save_file, load_file
import torch

tensors = {
   "a": torch.zeros((2, 2)),
   "b": torch.zeros((2, 3), dtype=torch.uint8)
}

save_file(tensors, "./model.safetensors")


# Now loading
loaded = load_file("./model.safetensors")

Developing

# inside ./safetensors/bindings/python
pip install .[dev]

Should be enough to install this library locally.

Testing

# inside ./safetensors/bindings/python
pip install .[dev]
pytest -sv tests/

Requirements

Requires Python: >=3.9
Details
PyPI
2026-02-24 14:13:06 +00:00
0
495 KiB
Assets (1)
Versions (1) View all
0.7.0 2026-02-24