Skip to main content

serva

Python client for the Serva encode/decode API. Encode files into the .serva format, decode them back, push datasets to the Hugging Face Hub, and load them into PyTorch.

Install

pip install serva

Grab an API key from serva.servamind.com and pass it to the client or set SERVA_API_KEY.

Encode and decode

from serva import Serva

client = Serva(api_key="sk_live_...")   # or set SERVA_API_KEY

result = client.encode("photo.raw", password="my-secret")
print(result.output_path, result.savings_percent)

client.decode("photo.serva", password="my-secret", output="photo.raw")

You decode with the same password you encoded with.

Hugging Face

Push encoded datasets to the Hub and pull them back. Set HF_TOKEN or pass hf_token=...; nothing extra to install.

result = client.encode("photo.raw", password="my-secret")
client.hub.push(result, repo_id="your-name/my-dataset")

path = client.hub.pull("your-name/my-dataset", "photo.serva")
client.decode(path, password="my-secret", output="photo.raw")

PyTorch

ServaDataset reads a folder of .serva files and returns each file's raw bytes as a tensor, the model trains on the encoded bytes. Point it at a directory, like torchvision's ImageFolder.

from serva.torch import ServaDataset
from torch.utils.data import DataLoader

ds = ServaDataset("data/train")
loader = DataLoader(ds, batch_size=32, shuffle=True)

for batch in loader:
    ...   # your model, your training step

The folder layout decides what you get:

  • Class subfolders (ants/*.serva, bees/*.serva) → (tensor, label).
  • A flat folder → just the tensor, for text or other unlabeled data.

Use label_fn when labels aren't in folder names (a CSV lookup, a regression target):

ds = ServaDataset("data/train", label_fn=lambda path: scores[path.stem])

By default files are padded to a fixed length so batches stack. To keep every byte and avoid padding side effects, use length=None with pad_collate it pads each batch only to its longest file and returns a mask marking real bytes, so the model ignores the padding:

from serva.torch import ServaDataset, pad_collate

ds = ServaDataset("data/train", length=None)
loader = DataLoader(ds, batch_size=32, collate_fn=pad_collate)

for bytes, mask, labels in loader:
    ...   # pass mask to your model so padded positions are ignored

ServaDataset only turns .serva files into tensors. Reshaping is plain PyTorch that's what transform and the DataLoader's collate_fn are for.

Configuration

Setting How Default
API key Serva(api_key=...) or SERVA_API_KEY — (required)
Base URL Serva(base_url=...) production API
Hugging Face token Serva(hf_token=...) or HF_TOKEN —

Errors

Everything raises a subclass of ServaError: AuthError (401), PaymentRequiredError (403), FileTooLargeError (413), RateLimitError (429), and HubError for a failed Hugging Face operation.

Versioning

Semantic versioning. Read the installed version from serva.__version__.

Metadata

Release files for serva 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for serva 0.3.0
File Size Uploaded Provenance Actions
serva-0.3.0.tar.gz 9.5 kB Without provenance Details for serva-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for serva 0.3.0
File Interpreter ABI Platform Actions
serva-0.3.0-py3-none-any.whl Python 3 none any Details for serva-0.3.0-py3-none-any.whl

Total release size: 20.0 kB

Release files / serva-0.3.0.tar.gz

Download URL serva-0.3.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c136438d63352d315b4b9b8b78d36c0e58296ebc77c6467601a9a49c15d74226
BLAKE2b-256 checksum
How to use checksums
9c3bb53db510a5153ec558bbf71f94caf26800f27908f26cb7c05fc5de1d280b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / serva-0.3.0-py3-none-any.whl

Download URL serva-0.3.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce466c7f0a7499a4fccc66b00d55bc10ac4fd370c12fd8fab71436ff563eb1a8
BLAKE2b-256 checksum
How to use checksums
80976d5ebb24c6345c9bb859c928399fcedc068f3421257ec38f4afde91e9715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for serva 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page