cozip

Python

  • Package cozip on PyPI, with wheels for Linux x86-64 and aarch64, macOS arm64 and x86-64 and Windows x86-64, on Python 3.10 or newer.
pip install cozip

Python calls libcozip through cffi, writes manifests with pyarrow and decodes them with DuckDB. The public names are write and its alias create, stage_metadata, stage_create, read, CozipError, lib, ffi and __version__.

Importing cozip loads the native library. pyarrow is imported when a writer function is first accessed, pandas when read is first accessed, and DuckDB when read is first called. The rules every binding shares are on the API overview.

Writing

write

cozip.write(out_path, table, temp_dir=None) -> str

Writes a Flat archive from a table, as Write describes, and returns its absolute path. cozip.create is the same function.

out_pathThe destination, as text or a path-like object. An existing file is replaced.
tableA pyarrow.Table with name, path and your columns.
temp_dirWhere the temporary manifest Parquet goes, created if missing. The default is the system temporary directory.
import pyarrow as pa
import cozip

table = pa.table({
    "name": ["a.txt", "data/b.bin"],
    "path": ["a.txt", "b.bin"],
    "split": ["train", "val"],
})
cozip.write("out.zip", table)

pyarrow writes the manifest and compresses it. A pandas DataFrame raises TypeError, so convert it first with pa.Table.from_pandas(df, preserve_index=False). Without preserve_index=False, a named index becomes a manifest column. The __index_level_N__ columns of an unnamed one are left out.

stage_metadata

cozip.stage_metadata(table) -> tuple[pyarrow.Table, list[tuple[str, str]]]

Plans the archive without writing anything, the first of the two stages. It returns the manifest as a pyarrow.Table and the (name, path) pairs in the same order. table is as for write.

metadata, paths = cozip.stage_metadata(table)
metadata.to_pylist()
[{'name': 'a.txt', 'offset': 127, 'size': 96, 'split': 'train'},
 {'name': 'data/b.bin', 'offset': 263, 'size': 40960, 'split': 'val'}]

stage_create

cozip.stage_create(out_path, paths, metadata_parquet, validate=True) -> str

Writes the archive around a manifest Parquet you wrote and returns its absolute path.

out_pathThe destination archive.
pathsA sequence of (name, source_path) pairs, in the manifest's row order.
metadata_parquetThe Parquet file, stored byte for byte as __metadata__.
validateA bool. The first mismatch with a fresh plan raises ValueError.
import pyarrow.parquet as pq

metadata, paths = cozip.stage_metadata(table)
pq.write_table(metadata, "metadata.parquet", compression="zstd")
cozip.stage_create("out.zip", paths, "metadata.parquet")

Reading

read

cozip.read(source, columns=None, location=True) -> pandas.DataFrame

Reads the manifest of a Flat archive into a DataFrame, one row per file. The arguments are described under Read.

sourceText or a path-like object, in one of the source forms.
columnsNone, or a list of str. With a list, the columns are name, offset, size, cozip:location, then the listed ones without repeats. An unknown name raises ValueError.
locationA bool.
url = "https://huggingface.co/datasets/asterisk-labs/cozip-api-fixtures/resolve/v0.1.0/data/cities.zip"
manifest = cozip.read(url, columns=["label", "continent"])
manifest[manifest.continent == "Europe"][["name", "offset", "size"]]
                   name  offset  size
4  cities/paris.geojson    1092   172
5   cities/oslo.geojson    1313   171

Types follow DuckDB's conversion to pandas. offset and size are uint64, strings use pandas' default string dtype, integer and boolean columns with nulls use the nullable dtypes such as Int32 and boolean, and binary columns, a GeoParquet geometry included, arrive as bytearray.

The process keeps one in-memory DuckDB database, and each read uses a cursor of its own, closed before read returns. A forked child opens a database of its own.

verify

cozip.verify(source) -> None

Checks an archive of any profile, as described under Verify. Returns None, or raises CozipError named after the broken rule, and imports neither pandas nor DuckDB.

Opening the files

Pass cozip:location to a GDAL reader, such as GeoPandas here or rasterio for a raster, or read the byte range yourself. Convert offset and size to int before the arithmetic. A local archive needs only f.seek(offset) and f.read(size).

import geopandas as gpd
import requests

paris = manifest[manifest.name == "cities/paris.geojson"].iloc[0]
gdf = gpd.read_file(paris["cozip:location"])

offset, size = int(paris["offset"]), int(paris["size"])
r = requests.get(url, headers={"Range": f"bytes={offset}-{offset + size - 1}"})   # 206, 172 bytes

GeoParquet manifests

With GeoPandas, plan first, add the geometry, write the Parquet and build the archive around it. to_pandas() keeps offset and size as uint64, and GeoPandas writes them back unchanged.

import geopandas as gpd

metadata, paths = cozip.stage_metadata(pa.table({"name": names, "path": files, "label": labels}))
gdf = gpd.GeoDataFrame(metadata.to_pandas(), geometry=geometries, crs="EPSG:4326")
gdf.to_parquet("metadata.parquet", index=False, compression="zstd", schema_version="1.1.0")
cozip.stage_create("dataset.zip", paths, "metadata.parquet")

With pyarrow alone, store WKB in a binary column, attach the geo key and call write.

import json
import shapely

geo = {"version": "1.1.0", "primary_column": "geometry",
       "columns": {"geometry": {"encoding": "WKB", "geometry_types": ["Polygon"]}}}
table = pa.table({
    "name": names,
    "path": files,
    "geometry": [shapely.to_wkb(g) for g in geometries],
}).replace_schema_metadata({"geo": json.dumps(geo)})
cozip.write("dataset.zip", table)

read returns the geometry as WKB in a bytearray. This turns it back into a GeoDataFrame.

df = cozip.read("dataset.zip")
gdf = gpd.GeoDataFrame(df, geometry=gpd.GeoSeries.from_wkb(df["geometry"].map(bytes)), crs="OGC:CRS84")

Errors

A check made in Python raises TypeError, ValueError or FileNotFoundError with the prefix cozip: , or cozip.read: for a manifest column. A failure inside libcozip raises cozip.CozipError, a RuntimeError whose text is [NAME] message, with the attributes code, an integer, name and message. The API overview lists the causes.

ValueError: cozip: input table has columns that differ only in case: 'label' and 'Label'; DuckDB, which reads manifests, cannot tell them apart
CozipError: [INVALID_ARGUMENT] entry 0 ('e') has a zero-byte payload; FLAT user entries must be non-empty
CozipError: [PROFILE] read_flat needs a Flat-profile archive (profile=1). Got profile=2 in: ...

Native library

cozip.lib exposes every C function through cffi, and cozip.ffi is its FFI object. Strings come back as char * values. The status, profile and source constants, such as COZIP_OK, COZIP_ERR_INVALID_ARGUMENT and COZIP_PROFILE_FLAT, are plain integers in cozip._core, not attributes of lib. The C page documents the functions.

cozip.__version__                                             # '2026.11.23', the package
cozip.ffi.string(cozip.lib.cozip_version_string()).decode()   # '2026.11.23', the loaded library

The library ships in the wheel as cozip/_lib/cozip.so, cozip.dylib or cozip.dll, without a lib prefix. Set COZIP_LIB_PATH to an absolute path before the import to load another build. The private module cozip._taco exists for the TACO package, and applications should not import it.