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 arbitrary 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 mock 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(('KEY', 'SUB-KEY'))
    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.1.1.tar.gz (4.8 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.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for swiftserialize-1.1.1.tar.gz
Algorithm Hash digest
SHA256 06aeadc386916fd14317ce182cc13fa8f7626c63eda6f042fffeb4d8662ba997
MD5 343e27ee7b9f42fe95b70208a353b762
BLAKE2b-256 369b3ea33929a8113919bcd5f404cba2920b01cfffadbe7cd5f4e96866f7b62b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swiftserialize-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dd47238cd10eb676d4f73572c8b5c21975bf495a55a8f1806ef78b3e5329c28
MD5 8e7e84548ffb6a09504da174c2088e7b
BLAKE2b-256 f5d44d2aec11eab84b49ddb20a222ca559c121ed8d544452a665908155e4bc60

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