Skip to main content

Python source code as a serialization format with automatic import resolution

Project description

pycodify

Python source code as a serialization format with automatic import resolution.

Quick Start

from pycodify import Assignment, generate_python_source
from dataclasses import dataclass

@dataclass
class Config:
    name: str = "default"
    value: int = 42

config = Config(name="production", value=100)
code = generate_python_source(Assignment("config", config))
print(code)
# Output:
# from __main__ import Config
# config = Config(name='production', value=100)

Why Python Source?

Format Diffable Inspectable Editable Type-preserving Cross-version
pickle
JSON/YAML
Python source Depends on imported APIs

Binary formats like pickle cannot be diffed, inspected, or edited. Text formats like JSON lose type information. Python source is diffable, inspectable, editable, and type-preserving, but replay still depends on the imported APIs and constructor signatures remaining compatible.

Features

  • Complete Executable Source: Generates imports + code, not just expressions
  • Type-Preserving: Enums, Paths, callables serialize as themselves
  • Collision Handling: Automatic aliasing for name collisions across modules
  • Clean Mode: Omit fields matching defaults for concise output
  • Extensible: Register custom formatters for domain-specific types

Documentation

Explicit mode is the default (clean_mode=False), preserving every field for reproducibility. Pass clean_mode=True only when concise, default-eliding source is desired.

Generated output is executable Python, not a sandboxed data format. Review it before execution and never call exec on source generated from untrusted objects, custom formatters, headers, or edited files.

Full documentation available at pycodify.readthedocs.io

Installation

pip install pycodify

License

MIT

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

pycodify-0.1.3.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

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

pycodify-0.1.3-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycodify-0.1.3.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pycodify-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9e591da6f904065a7b98312c942fad2d1bc0577bf202b2c8715379544fc8c8e7
MD5 e6e7fbead931456f653a1af509909cfc
BLAKE2b-256 cd022f7e8467befb466c5e271227d6764b0a5ad775d60ee5ea8f09ccc6c192b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycodify-0.1.3.tar.gz:

Publisher: publish.yml on OpenHCSDev/pycodify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pycodify-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pycodify-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7f855880a67bd65c7f5d0d33d07486318367cb082df37c42e1037b66c3516142
MD5 26379b5893059e7512d078c95c8c3120
BLAKE2b-256 42dd741619c2334766bbed55b6860ecbd54849cd28452c45b14d6c05a41ef21c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycodify-0.1.3-py3-none-any.whl:

Publisher: publish.yml on OpenHCSDev/pycodify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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