Skip to main content

A simple way to read and write structured data. Easily extendable to support custom data formats.

Project description

Copyright (c) 2025 Sean Yeatts. All rights reserved.

A simple way to read and write structured data. Easily extendable to support custom data formats.

Key Features

  • Easily read, write, and convert between structured data formats ( ex. json, yaml ).

  • Provides convenience methods for de-nesting / re-nesting hierarchical datasets.

  • Encode to binary for middleman services ( ex. encryption ).

Quickstart

Example - conversion between two structured data formats :

# IMPORTS
from swiftserialize import JSONSerializer, YAMLSerializer


# MAIN DEFINITION
def main() -> None:

    # [1] Prepare some input / output files
    file_in = "examples/data/translate/input.yaml"
    file_out = "examples/data/translate/output.json"

    # [2] Read data from input file
    with open(file_in, 'rb') as target:
        data = target.read()

    # [3] Translate between structured data formats
    decoded: dict = YAMLSerializer('utf-8').decode(data)
    encoded: bytes = JSONSerializer('utf-8').encode(decoded)

    # [4] Write data to output file
    with open(file_out, "wb") as target:
        target.write(encoded)

    # [5] Visualize results
    print(decoded)
    print(encoded)


# ENTRY POINT
if __name__ == "__main__":
    main()

Example - introducing a middleman service :

# IMPORTS
from swiftserialize import YAMLSerializer


# MOCKUP FUNCTIONS
def encrypt(data: bytes) -> bytes:
    """Placeholder mock encryption service."""
    return data


# MAIN DEFINITION
def main() -> None:

    # [1] Prepare some input / output files
    file_in = "examples/data/middleman/input.yaml"
    file_out = "examples/data/middleman/output.bin"

    # [2] Read data from input file
    with open(file_in, 'rb') as target:
        data = target.read()

    # [3] Inject middleman services ( ex: encryption )
    serializer  = YAMLSerializer('utf-8')
    decoded     = serializer.decode(data)
    encrypted   = encrypt(decoded)
    encoded     = serializer.encode(encrypted)

    # [4] Write data to output file
    with open(file_out, "wb") as target:
        target.write(encoded)


# ENTRY POINT
if __name__ == "__main__":
    main()

Example - manipulating nested datasets :

# IMPORTS
from swiftserialize import YAMLSerializer


# MAIN DEFINITION
def main() -> None:

    # [1] Read some data from an input file
    with open("examples/data/nesting/test.yaml", "rb") as target:
        data = target.read()

    # [2] Conveniently unpack / pack nested datasets
    serializer  = YAMLSerializer('utf-8')
    original    = serializer.decode(data)
    unpacked    = serializer.unpack(original)
    packed      = serializer.pack(unpacked)

    # [3] Visualize result
    print(original)
    print(unpacked)
    print(packed)

    # [4] Keys for flattened datasets are represented as tuples
    value = unpacked.get(('KEY-2', 'KEY-2A'))
    print(value)


# ENTRY POINT
if __name__ == "__main__":
    main()

Installation

Prerequisites:

  • Python 3.8 or higher is recommended

  • pip 24.0 or higher is recommended

For a pip installation:

Open a new Command Prompt. Run the following command:

py -m pip install swiftserialize

For a local installation:

Extract the contents of this module to a safe location. Open a new terminal and navigate to the top level directory of your project. Run the following command:

py -m pip install "DIRECTORY_HERE\swiftserialize\dist\swiftserialize-1.0.0.tar.gz"
  • DIRECTORY_HERE should be replaced with the complete filepath to the folder where you saved the SwiftSerialize module contents.

  • Depending on the release of SwiftSerialize you’ve chosen, you may have to change 1.0.0 to reflect your specific version.

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

swiftserialize-1.2.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

swiftserialize-1.2.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file swiftserialize-1.2.0.tar.gz.

File metadata

  • Download URL: swiftserialize-1.2.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for swiftserialize-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8055d3f000433bb5a31b376f42e501c175a2f8e44037393661c25d071ab8ec39
MD5 aa303fe7cab77e03506402417c3a861a
BLAKE2b-256 120361c8fdd7bb172a083be1d37a6b429072018a54d799d9b284cecd1c662d4b

See more details on using hashes here.

File details

Details for the file swiftserialize-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: swiftserialize-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for swiftserialize-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26b6f229e9b6b6fbb79c3e4b09f9923da89649148f350211c3794fc539d35a3c
MD5 f4afb82130070199bd79cd9565dd73b9
BLAKE2b-256 f5acb58a6453d2b6ac7ef6f4eccad37aac66250cb95c664aa6620e1a533eb08b

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