Skip to main content

Python library for parsing, validating, and serializing TON (Text Object Notation) files

Project description

DevPossible.Ton - Python Library

Developed by DevPossible, LLC Contact: support@devpossible.com

Python implementation of the TON (Text Object Notation) parser, serializer, formatter, and validator.

Installation

pip install devpossible-ton

Quick Start

import devpossible_ton as ton

# Parse TON data
document = ton.parse("""
{
  name: "My App"
  version: "1.0.0"
}
""")

# Access data
root = document.get_root()
print(root.get('name'))  # "My App"

# Serialize back to TON
serialized = ton.serialize(document)
print(serialized)

# Format TON files
from devpossible_ton import TonFormatter
formatted = TonFormatter.pretty(ton_text)

Features

  • ✅ Full TON specification parser with async support
  • ✅ Comprehensive schema validation with 30+ validation rule types
  • ✅ Code formatter with compact and pretty styles
  • ✅ Type annotations and hints
  • ✅ Enum and EnumSet support
  • ✅ Array support with mixed types
  • ✅ Pretty and compact serialization
  • ✅ Async file operations
  • ✅ Schema collections and definitions

Advanced Usage

Schema Validation

from devpossible_ton import (
    TonSchemaDefinition, 
    TonPropertySchema, 
    ValidationRuleType, 
    TonValidationRule
)

# Create a schema
schema = TonSchemaDefinition('User')
name_prop = TonPropertySchema('name', 'string')
name_prop.add_validation(TonValidationRule(ValidationRuleType.REQUIRED))
name_prop.add_validation(TonValidationRule(ValidationRuleType.MIN_LENGTH, 3))
schema.add_property('name', name_prop)

Formatting

from devpossible_ton import TonFormatter, TonFormatStyle

# Format with different styles
compact = TonFormatter.compact(ton_text)
pretty = TonFormatter.pretty(ton_text)
sorted_output = TonFormatter.sorted(ton_text)

# Async formatting
import asyncio
formatted = await TonFormatter.format_file_async('input.ton', TonFormatStyle.PRETTY)

Serialization Options

from devpossible_ton import TonSerializeOptions, TonFormatStyle

# Use presets
options = TonSerializeOptions.compact()
options = TonSerializeOptions.pretty()
options = TonSerializeOptions.optimized()

# Custom options
options = TonSerializeOptions(
    format_style=TonFormatStyle.PRETTY,
    indent_size=2,
    sort_properties=True,
    include_header=True
)

License

MIT License - Copyright © 2024 DevPossible, LLC

Support

DevPossible, LLC Email: support@devpossible.com


© 2024 DevPossible, LLC. All rights reserved.

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

devpossible_ton-0.1.3.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

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

devpossible_ton-0.1.3-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file devpossible_ton-0.1.3.tar.gz.

File metadata

  • Download URL: devpossible_ton-0.1.3.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for devpossible_ton-0.1.3.tar.gz
Algorithm Hash digest
SHA256 763485c9f441426cc1604de9e0a2b4ffd2aa7f8fec8a37f922205e59d932d749
MD5 61b6e13abe69cb6e568349847cc346d3
BLAKE2b-256 c8f038af4f4fc48b8efd1d9bafc3317b4b4a5811e17fc4ff82edecd735552f3c

See more details on using hashes here.

File details

Details for the file devpossible_ton-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for devpossible_ton-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 04515128580566786d03babb0271943b5c8ce1d5ade2ed7cfa829f78227ee386
MD5 0bcf9922ba499c5a5ecef5f1a913661e
BLAKE2b-256 ad8036ea6f0414205cd2b8dbf15112c76c6eb2f9120c3f59a79087e653d9e3a0

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