Skip to main content

Serialization library or the HiPack interchange format

Project description

Documentation Status Build Status Code Coverage

hipack is a Python module to work with the HiPack serialization format. The API is intentionally similar to that of the standard json and pickle modules.

Features:

  • Both reading, and writing HiPack version 1 is supported. The following extensions are implemented as well:

    (Note that extensions defined in HEPs are subject to change while they are being discussed as proposals.)

  • Small, self-contained, pure Python implementation.

  • Compatible with both Python 2.6 (or newer), and 3.2 (or newer).

Usage

Given the following input file:

# Configuration file for SuperFooBar v3000
interface {
  language: "en_US"
  panes {
    top: ["menu", "toolbar"]  # Optional commas in lists
    # The colon separating keys and values is optional
    bottom
      ["statusbar"]
  }
  ☺ : True  # Enables emoji
  Unicode→Suþþorteð? : "Indeed, Jürgen!"
}

# Configure plug-ins
plugin: {
  preview  # Whitespace is mostly ignored
  {
    enabled: true
    timeout: 500  # Update every 500ms
  }
}

Note that the : separator in between keys and values is optional, and can be omitted. Also, notice how white space —including new lines— are completely meaningless and the structure is determined using only braces and brackets. Last but not least, a valid key is any Unicode character sequence which does not include white space or a colon.

The following code can be used to read it into a Python dictionary:

import hipack
with open("superfoobar3000.conf", "rb") as f:
  config = hipack.load(f)

Conversions work as expected:

  • Sections are converted into dictionaries.

  • Keys are converted conveted to strings.

  • Text in double quotes are converted to strings.

  • Sections enclosed into { } are converted to dictionaries.

  • Arrays enclosed into [ ] are converted to lists.

  • Numbers are converted either to int or float, whichever is more appropriate.

  • Boolean values are converted to bool.

The following can be used to convert a Python dictionary into its textual representation:

users = {
  "peter": {
    "uid": 1000,
    "name": "Peter Jøglund",
    "groups": ["wheel", "peter"],
  },
  "root": {
    "uid": 0,
    "groups": ["root"],
  }
}

import hipack
text = hipack.dumps(users)

When generating a textual representation, the keys of each dictionary will be sorted, to guarantee that the generated output is stable. The dictionary from the previous snippet would be written in text form as follows:

peter: {
  name: "Peter Jøglund"
  groups: ["wheel" "peter"]
  uid: 1000
}
root: {
  groups: ["root"]
  uid: 0
}

Installation

The stable releases are uploaded to PyPI, so you can install them and upgrade using pip:

pip install hipack

Alternatively, you can install development versions —at your own risk— directly from the Git repository:

pip install -e git://github.com/aperezdc/hipack-python

Development

If you want to contribute, please use the usual GitHub workflow:

  1. Clone the repository.

  2. Hack on your clone.

  3. Send a pull request for review.

If you do not have programming skills, you can still contribute by reporting issues that you may encounter.

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

hipack-14.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

hipack-14-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file hipack-14.tar.gz.

File metadata

  • Download URL: hipack-14.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for hipack-14.tar.gz
Algorithm Hash digest
SHA256 0d14e85afca790aaf15822a117cee58e3637ab9f8fe889f55d25e049e68a82ba
MD5 155eef2d5bef7fcd8ccd388bdc797278
BLAKE2b-256 1f664117c81a12339e65377699da1c7813d79d31e16500e1e8295925e9c770d2

See more details on using hashes here.

File details

Details for the file hipack-14-py3-none-any.whl.

File metadata

  • Download URL: hipack-14-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for hipack-14-py3-none-any.whl
Algorithm Hash digest
SHA256 07953809a025cc503fecfa55a0a791007d793ebd0a912f8e7b99cc738ed205f1
MD5 b99dbb21942c349312730b0db6470c97
BLAKE2b-256 2e7f6920871259d0cbfa46b419986b566a0d1ca15b22e8a9d2592afd8d6d8c14

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page