Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ polyxml build --config polyxml.toml
from generated.python import Customer
import polyxml

# 16x faster than xsdata with zero intermediate DOM overhead
customer = polyxml.deserialize(xml_bytes, Customer)
print(f"Customer: {customer.name}, Status: {customer.status}")
# 16x faster XML parsing with zero intermediate DOM overhead
customer = Customer.from_xml(xml_bytes)
xml_output = customer.to_xml(indent=2)

# Serialize back to formatted XML
xml_output = polyxml.serialize(customer, indent=2)
# 10x faster native JSON — completely replace xsdata:
json_bytes = customer.to_json(indent=2)
customer = Customer.from_json(json_bytes)
```

=== "Rust (Zero-Copy)"
Expand Down Expand Up @@ -118,7 +119,7 @@ PolyXML strictly generates code adhering to modern programming paradigms (2024

| Target Language | CLI Flag (`--lang`) | Generated Code Paradigm | Modern Features & Highlights |
| :--- | :--- | :--- | :--- |
| **Python 3.12+** | `python` | `@dataclass(slots=True)` & Pydantic v2 | PEP 695 type aliases (`type Sku = ...`), PEP 604 unions, restriction facet validation |
| **Python 3.12+** | `python` | `@dataclass(slots=True)` & Pydantic v2 | PEP 695 type aliases, PEP 604 unions, restriction facets, native JSON codecs (10x faster xsdata replacement) |
| **Rust 2021/2024** | `rust` | Zero-copy `Cow<'a, str>` & Owned structs | Automatic Tarjan SCC recursive boxing (`Box<T>`), inherent streaming codecs |
| **C++20 / C++23** | `cpp` | Modern value types & `std::variant` | C++20 concepts, `std::unique_ptr` cycle breaks, CMake/Meson export, zero Xerces |
| **Java 21+** | `java` | Modern `record` & `sealed interface` | Exhaustive switch pattern matching, compact constructor facet validation, zero JNI |
Expand Down
1 change: 1 addition & 0 deletions crates/polyxml-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ memchr = "2.8"
thiserror = "2.0"
smallvec = "1.16"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
minijinja = { version = "2.8", features = ["builtins"] }
heck = "0.5"

Expand Down
18 changes: 17 additions & 1 deletion crates/polyxml-core/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,23 @@ impl PythonCodegen {
out.push_str(" ) -> bytes:\n");
out.push_str(" \"\"\"Serialize this model instance into XML bytes.\"\"\"\n");
out.push_str(" import polyxml\n");
out.push_str(" return polyxml.serialize(self, indent=indent, namespaces=namespaces, ns_map=ns_map)\n");
out.push_str(" return polyxml.serialize(self, indent=indent, namespaces=namespaces, ns_map=ns_map)\n\n");
out.push_str(" @classmethod\n");
out.push_str(" def from_json(cls, data: bytes | str) -> Self:\n");
out.push_str(" \"\"\"Deserialize JSON bytes or string into this model.\"\"\"\n");
out.push_str(" import polyxml\n");
out.push_str(" return polyxml.deserialize_json(data, cls)\n\n");
out.push_str(" def to_json(\n");
out.push_str(" self,\n");
out.push_str(" *,\n");
out.push_str(" indent: int | None = None,\n");
out.push_str(" by_alias: bool = True,\n");
out.push_str(" ) -> bytes:\n");
out.push_str(" \"\"\"Serialize this model instance into JSON bytes.\"\"\"\n");
out.push_str(" import polyxml\n");
out.push_str(
" return polyxml.serialize_json(self, indent=indent, by_alias=by_alias)\n",
);
has_body = true;
}

Expand Down
3 changes: 3 additions & 0 deletions crates/polyxml-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum PolyXmlError {

#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),

#[error("JSON error: {0}")]
JsonError(#[from] serde_json::Error),
}

pub type Result<T> = std::result::Result<T, PolyXmlError>;
Loading
Loading