Skip to main content

Python wrapper for zcompact - JSON compaction with queryable ID index

Project description

zcompact

Python wrapper for zcompact - JSON compaction with queryable ID index.

Requirements

The zcompact CLI must be installed:

brew tap zzmarks26/zcompact
brew install zcompact

Installation

pip install /path/to/Zcompact/python

Usage

Create an archive from .gz files

from zcompact import Archive

# Create archive with secondary index
archive = Archive.create_from_files(
    "data.jcpk",
    ["file1.json.gz", "file2.json.gz"],
    id_field="id",
    index_field="_domain_uuid"
)

Open an existing archive

from zcompact import Archive

archive = Archive("data.jcpk")

Query by primary ID

# Returns dict or None
record = archive.get("user-123")

# Raises RecordNotFoundError if not found
record = archive.get_or_raise("user-123")

Query by secondary index

# Get all records for a company
records = archive.query_index("company-uuid-here")

for record in records:
    print(record["name"])

Search by ID prefix

# Get IDs starting with "user-"
ids = archive.search("user-", limit=100)

Insert/Update/Delete

# Insert
archive.insert("new-id", {"id": "new-id", "name": "Alice"})

# Update
archive.update("new-id", {"id": "new-id", "name": "Alice Smith"})

# Delete
archive.delete("new-id")

# Compact to reclaim space
archive.compact()

Get stats

stats = archive.stats()
print(f"Records: {stats['active_records']}")
print(f"Compression ratio: {stats['compression_ratio']}x")

Example: AWS S3 workflow

import boto3
from zcompact import Archive

s3 = boto3.client('s3')

# Download .gz files from S3
files = []
for key in ['data/part1.json.gz', 'data/part2.json.gz']:
    local_path = f"/tmp/{key.split('/')[-1]}"
    s3.download_file('my-bucket', key, local_path)
    files.append(local_path)

# Create searchable archive
archive = Archive.create_from_files(
    "records.jcpk",
    files,
    id_field="id",
    index_field="_domain_uuid"
)

# Query
company_records = archive.query_index("some-company-uuid")

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

zcompact-1.0.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

zcompact-1.0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file zcompact-1.0.1.tar.gz.

File metadata

  • Download URL: zcompact-1.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zcompact-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bc17d7a928e5a048f9917a4c1835fe5658b14ff4bf18cd3b71600ca93d1c5c17
MD5 75adad6b030eafd3e74f0d2d488b30c4
BLAKE2b-256 3376529c3703128188d5e90bb6316d0e80c08c90411941499f873477f4243f76

See more details on using hashes here.

Provenance

The following attestation bundles were made for zcompact-1.0.1.tar.gz:

Publisher: publish.yml on zzmarks26/Zcompact

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zcompact-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: zcompact-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zcompact-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 99a1a6ac6750725d126799527ff6c6dc1b279602c1e4dc2642062e1c889997e2
MD5 eeaabb10637b556eaf95cff9e9e53ba9
BLAKE2b-256 025b6ba206040c16e16ae63db6c13bd253154a0299c84d90ad5a4864eeb44dc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for zcompact-1.0.1-py3-none-any.whl:

Publisher: publish.yml on zzmarks26/Zcompact

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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