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, Inc. All rights reserved.

SwiftSerialize

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. data encryption ).

Quickstart

Example - conversion between two structured data formats :

# IMPORTS
from swiftserialize import JSONSerializer, YAMLSerializer


# MAIN DEFINITION
def main() -> None:

    # [1] Prepare some files
    file_1 = fr"cache\test.yaml"
    file_2 = fr"cache\test.json"

    # [2] Load structured data directly into a Python dict
    data: dict = YAMLSerializer().load(file_1)

    # [3] Convert to a different structured format
    JSONSerializer().save(data, file_2)


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

Example - introducing a middleman service :

# IMPORTS
from swiftserialize import YAMLSerializer


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


# MAIN DEFINITION
def main() -> None:

    # [1] Prepare some files
    file_1 = fr"cache\test.yaml"
    file_2 = fr"cache\test.bin"

    # [2] Convert to binary for middleman services ( ex. encryption )
    data        = YAMLSerializer().load(file_1)
    encoded     = YAMLSerializer().encode(data)
    encrypted   = encrypt(encoded)

    # [3] Serialize the modified data using the same serializer
    YAMLSerializer().serialize(encrypted, file_2)


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

Example - manipulating nested datasets :

# IMPORTS
from swiftserialize import YAMLSerializer


# MAIN DEFINITION
def main() -> None:

    # [1] Prepare a file
    file = fr"cache\test.yaml"

    # [2] Nested datasets can be conveniently "unpacked" into single key-value pairs
    original:   dict = YAMLSerializer().load(file)
    unpacked:   dict = YAMLSerializer().unpack(file)

    # [3] Nesting operations can be done directly with Python dicts
    flattened:  dict = YAMLSerializer().flatten(original)
    folded:     dict = YAMLSerializer().fold(flattened)

    print(original)
    print(unpacked)
    print(flattened)
    print(folded)

    # [4] Keys for flattened datasets are represented as tuples
    value = flattened.get(('PARAMETER', 'SUB-PARAMETER'))
    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.0.0.tar.gz (4.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.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: swiftserialize-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for swiftserialize-1.0.0.tar.gz
Algorithm Hash digest
SHA256 53e8be7f1c078e61b4257802cd18ee5ebaee95b95dd0fd23ca35fd77266a8214
MD5 4c71d5c7a96a2ad1e8d5d3320a37757f
BLAKE2b-256 dca240f49298b8fc7f1f3d9c87ef20148948c30e8d9b17667d148e6f5f35f167

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swiftserialize-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for swiftserialize-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6948dde3c862e1869524c3fbb48d09dcd100b023e9fff5bb039fc96135413d92
MD5 d677d5598c6564bb22313a86bc594c61
BLAKE2b-256 3cecd1a7c6f9810a1c596698cb62880c74eaa2531acbbf8b9d78b69535f9c6be

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