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
Metadata
Release files for pycodify 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycodify-0.2.1.tar.gz | 29.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycodify-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.6 kB
Release files / pycodify-0.2.1.tar.gz
| Download URL | pycodify-0.2.1.tar.gz |
|---|---|
| Size | 29.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
872539cd676038525ee70b74ac6dfddfe1a310c8f756f444a32c05676c23f798
|
|
BLAKE2b-256 checksum How to use checksums |
21e5a6d7f8d724b41c1385941d72011a4c9e3a989b3f80e24a8a052b95956b1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / pycodify-0.2.1-py3-none-any.whl
| Download URL | pycodify-0.2.1-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3286d925fed2ef4dc5e65cebdb7a2939e3a38a7ce07b4e705bdaa6fd47928bf
|
|
BLAKE2b-256 checksum How to use checksums |
e014bba29c6e8766fa1b6ba90e0ae83d58e78b073f1fbd04e20383823d933e9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|