Observed since 20 Oct, 17:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Automatic type conversion library for Python
Automatic type conversion for Python.
autocast is a lightweight library that automatically converts objects from one type to another using a graph of registered transformation functions. If a direct conversion isn't available, autocast finds the shortest path through intermediate types to get you the result you need.
It comes with built-in support for NumPy, PyTorch, Open3D, and OmegaConf, but it is designed to be easily extensible for your own classes.
pip install acaster
To install with support for all optional backends (PyTorch, Open3D, etc.):
pip install "acaster[all]"
The core function is acast(object, target_type).
import torch
import numpy as np
from autocast import acast
# Create a Torch tensor
tensor = torch.ones((3, 3))
# Automatically convert to NumPy array
array = acast(tensor, np.ndarray)
print(type(array))
# <class 'numpy.ndarray'>
Build an Open3D Point Cloud directly from PyTorch tensors or Numpy arrays without manually converting them to Open3D Vector3dVector:
import open3d as o3d
import torch
from autocast import acast
H, W = 448, 448
rgb_image = torch.rand(H, W, 3) # H x W x 3
predicted_pts = torch.rand(H * W, 3) # H * W x 3
# Cast a tuple of (points, colors) directly to a PointCloud
pcd = acast((predicted_pts, rgb_image), o3d.geometry.PointCloud)
print(type(pcd))
# <class 'open3d.cpu.pybind.geometry.PointCloud'>
# o3d.io.write_point_cloud("output.ply", pcd)
autocast automatically handles nested lists and dictionaries.
data = {
"points": torch.rand(100, 3),
"colors": torch.rand(100, 3),
"meta": [torch.tensor(1.0), torch.tensor(2.0)]
}
# Convert everything inside the dict to NumPy arrays
numpy_data = acast(data, np.ndarray)
print(type(numpy_data['points']))
# <class 'numpy.ndarray'>
A -> B and B -> C, autocast can do A -> C automatically.torch or open3d) are only imported if they are installed in your environment.| From | To | Notes |
|---|---|---|
torch.Tensor | numpy.ndarray | Zero-copy where possible |
numpy.ndarray | torch.Tensor | |
list/tuple | np.ndarray | |
open3d.geometry | numpy.ndarray | Vector3dVector support |
omegaconf.ListConfig | list/dict | Converts to native containers |
You can register your own casts using the add_acast function or the @acaster decorator.
from autocast import acaster, acast
class Cat:
def speak(self): return "Meow"
class Dog:
def speak(self): return "Woof"
# Register a function that converts Cat -> Dog
@acaster(Cat, Dog)
def cat_to_dog(cat_instance):
return Dog()
my_cat = Cat()
my_dog = acast(my_cat, Dog)
from autocast import add_acast
def str_to_int(s):
return int(s)
add_acast(str, int, str_to_int)
print(acast("123", int)) # 123
We welcome contributions! If you want to add support for a new library (e.g., Pandas, Polars, JAX), please submit a Pull Request.
git checkout -b feature/new-cast)To run the tests, install pytests and run python -m pytest.
To release a new version of acaster:
version = "x.y.z" in pyproject.toml.git tag v0.x.y
git push origin --tags
rm -rf dist/
python -m build
twine upload dist/*
Distributed under the MIT License. See LICENSE for more information.
The idea for this library was inspired by erezsh/autocast.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0.1 | 9 Feb 2026 | 6 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 17:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:e5e70642d72d289118a22292cbf63cd84e4980343e128584467e7337572d5144