Skip to main content

No project description provided

Project description

jiter-pupy: Pure Python jiter Implementation

A drop-in replacement for the jiter package that is API-compatible with the original Rust-based implementation, but uses only Python's standard library json module.

Features

  • 100% API compatible with the Rust-based jiter package
  • Pure Python implementation using only the standard library
  • No compilation required - works anywhere Python runs
  • Supports all jiter features:
    • String caching for performance
    • Partial JSON parsing
    • Different float modes (float, decimal, lossless-float)
    • Special value handling (Infinity, NaN)
    • Duplicate key detection

Installation

pip install jiter-pupy

Usage

import jiter_pupy as jiter

# Parse JSON data
data = jiter.from_json(b'{"name": "John", "age": 30}')
print(data)  # {'name': 'John', 'age': 30}

# Use different float modes
from decimal import Decimal
data = jiter.from_json(b'{"value": 123.456}', float_mode="decimal")
print(isinstance(data["value"], Decimal))  # True

# Handle partial JSON
incomplete = b'{"name": "John", "address": {"city": "New Yor'
data = jiter.from_json(incomplete, partial_mode=True)
print(data)  # {'name': 'John'}

# Include trailing strings
data = jiter.from_json(incomplete, partial_mode="trailing-strings")
print(data)  # {'name': 'John', 'address': {'city': 'New Yor'}}

# Catch duplicate keys
try:
    jiter.from_json(b'{"foo": 1, "foo": 2}', catch_duplicate_keys=True)
except ValueError as e:
    print(e)  # Detected duplicate key "foo" at line 1 column 18

# String caching
jiter.cache_clear()
jiter.from_json(b'{"foo": "bar"}')
print(jiter.cache_usage() > 0)  # True

API

def from_json(
    json_data: bytes,
    /,
    *,
    allow_inf_nan: bool = True,
    cache_mode: Literal[True, False, "all", "keys", "none"] = "all",
    partial_mode: Literal[True, False, "off", "on", "trailing-strings"] = False,
    catch_duplicate_keys: bool = False,
    float_mode: Literal["float", "decimal", "lossless-float"] = "float",
) -> Any:
    """Parse input bytes into a JSON object."""

def cache_clear() -> None:
    """Reset the string cache."""

def cache_usage() -> int:
    """Get the size of the string cache in bytes."""

class LosslessFloat:
    """Represents a float from JSON, preserving the exact string representation."""

Performance

While this implementation prioritizes API compatibility over raw performance, it still offers benefits:

  • String caching can improve performance in scenarios with repeated strings
  • No compilation required, works anywhere Python runs
  • Useful as a fallback when the compiled jiter package isn't available

Development

This project uses Hatch for development workflow management.

Setup Development Environment

# Install hatch if you haven't already
pip install hatch

# Create and activate development environment
hatch shell

# Run tests
hatch run test

# Run tests with coverage
hatch run test-cov

# Run benchmarks
hatch run bench

# Run linting
hatch run lint

# Format code
hatch run fix

License

MIT License

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

jiter_pupy-0.8.2.tar.gz (67.2 kB view details)

Uploaded Source

Built Distribution

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

jiter_pupy-0.8.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file jiter_pupy-0.8.2.tar.gz.

File metadata

  • Download URL: jiter_pupy-0.8.2.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for jiter_pupy-0.8.2.tar.gz
Algorithm Hash digest
SHA256 ac16918a94febaad62638178a63e1a41f5329204b70e482cd30d94d49a24e4b5
MD5 8e66886632e59a90c3f41e7e86ae143e
BLAKE2b-256 da4d262cdc972e1237e6e738c9c37506051b36af4f48668735a931a2393e68a8

See more details on using hashes here.

File details

Details for the file jiter_pupy-0.8.2-py3-none-any.whl.

File metadata

File hashes

Hashes for jiter_pupy-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9dcc2789a6cae770981059687bee54739c22f6086ba462d5853ca70f1c9bfcfe
MD5 83496a99a3cb05a6a9314ce32e3f8343
BLAKE2b-256 b0d1dd80522eddc4db7ca1c7d9c56cdb502bcc3f47b5983951becf5a36e41991

See more details on using hashes here.

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