Skip to main content

SwiftSerialize

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.

Metadata

Release files for swiftserialize 1.3.1

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

Source distribution (sdist)

Source distribution for swiftserialize 1.3.1
File Size Uploaded
swiftserialize-1.3.1.tar.gz 6.4 kB Details

Built distribution (wheel)

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

Total release size: 18.5 kB

Release files / swiftserialize-1.3.1.tar.gz

Download URL swiftserialize-1.3.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
45e774f06dd10cd2a2d09dc32ab69595f9180d75867e6f5a6a292aab2d57a082
BLAKE2b-256 checksum
How to use checksums
9b395f89a987d310c637bf12187281aeedb242905dff840a5f09b035efe6e091
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release files / swiftserialize-1.3.1-py3-none-any.whl

Download URL swiftserialize-1.3.1-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca5d0e4d1881c77bdf5f2f29aad98bf8876e8aa9c577162ccdb5365c1ed573a0
BLAKE2b-256 checksum
How to use checksums
70e5767cf11a9f11a5c6a39a0dda7a64e0775280464318bca3ec6922f3e9b6cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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