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.

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.2.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.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: swiftserialize-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a6b84f261bf18963c3b06ca19fa3060b36dbc6f869cd39e32247f11dfff36810
MD5 f283ce4240b4e76aaaeb9d3d36ca6bda
BLAKE2b-256 916d0fbd92fbb6dc481f3e3284f54c2db8798e3cd58ef08f4645cd22041ba651

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swiftserialize-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 376ddc7517eedca5e48626e9f225057a7610880f382d500d3c7eda899c2b6b13
MD5 0c274541e11b0afa9e899f6c4e0f8587
BLAKE2b-256 d9cd659fc2ad2359627d700f9df92cff65a582d1237ae30fa82eda79e8ce6e42

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