Skip to main content

serva

Python client for the Serva encode/decode API. Encode files and data into the .serva format, decode them back, read a file's public index without its password, 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. Encoding and decoding need one; reading a file's public index does not.

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.

encode also takes the three settings any of them unset and the service default is used.

client.encode(
    "photo.raw",
    password="my-secret",
    hv_dim=512,          
    hv_seed=7,          
)

Encode data

Rows of scalars are encoded to a .serva like any file. The rows go in the locked part their hypervectors become the file's public index, one per row, so you read them back.

result = client.encode_data(
    [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]],
    hv_dim=8192,
    output="rows.serva",
)
print(result.rows, result.dimension, result.output_path)

client.hypervectors("rows.serva")   # one hypervector per row

Reading the public index

A .serva keeps its header and hypervectors unencrypted at the front, so these read straight off your disk. No request, no password, and they work offline.

info = client.info("photo.serva")
print(info.n_rows, info.dimension, info.encrypted)

client.hypervectors("photo.serva")      # every row's hypervector
client.get_hv("photo.serva", 0)         # one row

Files encoded before the index was stored uncompressed can only be read by the service; hypervectors and get_hv say so rather than returning something wrong.

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 to encode or decode)
Base URL Serva(base_url=...) production API
Hugging Face token Serva(hf_token=...) or HF_TOKEN —

Progress

Both calls draw a bar when stderr is a terminal, one line per phase.

  upload        ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% 0:00:32
  encode/decode ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% 0:00:16
  download      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% 0:00:01

The upload and download lines track bytes moved. The middle line is named after whichever call you made and tracks the work on the server, from the time it reports as still to go.

Errors

Everything raises a subclass of ServaError, connection failures and timeouts included, so a single except ServaError covers all of them.

Error Raised when
AuthError the API key is missing, invalid, or expired
PasswordError the password does not decrypt this file
PaymentRequiredError a payment method is needed to continue
AccessDeniedError the account may not touch this resource
NotFoundError the task, job, or file is gone from the server
ConflictError the request clashes with work already done
ValidationError the input or the request was rejected before any work started
FileTooLargeError the file is over the service maximum
RateLimitError too many requests in too short a window
ServiceError the service failed while handling the request
NetworkError the service could not be reached at all
RequestTimeoutError the service did not answer in time
HubError a Hugging Face operation failed

Each one carries the message the service wrote, plus status_code and code, so you can branch on the cause without matching on message text.

try:
    client.decode("photo.serva", password="wrong")
except ServaError as exc:
    print(exc)          # Password is incorrect or file is corrupted
    print(exc.code)     # incorrect_password

Versioning

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

Metadata

Release files for serva 0.5.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.5.0
File Size Uploaded Provenance Actions
serva-0.5.0.tar.gz 20.2 kB Without provenance Details for serva-0.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 42.3 kB

Release files / serva-0.5.0.tar.gz

Download URL serva-0.5.0.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
58c1e7f67ab612c2d6aa578fc4dcd057620014934cbf1a49e032dfa32613ccff
BLAKE2b-256 checksum
How to use checksums
49f0ce689ed8b1ac40821e299028a35a3f400136e349ada6e2bdd72db979c380
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.5.0-py3-none-any.whl

Download URL serva-0.5.0-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae0ebb68e13ae4ea497064b2fa36b3fb783c38017c2bfc5ae2ed0ca0c9b52842
BLAKE2b-256 checksum
How to use checksums
4488e45c629d261646e6683ffa675e4e786908746de92d96f2e8eae354f9934b
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.5.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