Skip to content
 
 

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Pythonize

WIP: Most functionality of this crate is still stubbed out. Please don't try to use this yet - unless you're interested in submitting PRs to help finish it off :)

This is an experimental serializer for Rust's serde ecosystem, which can convert Rust objects to Python values and back.

At the moment the Python structures it produces should be very similar to those which are produced by serde_json; i.e. calling Python's json.loads() on a value encoded by serde_json should produce an identical structure to that which is produced directly by pythonize.

Usage

Pythonize has two public APIs: pythonize and depythonize.

use serde::{Serialize, Deserialize};
use pyo3::{Python, py_run};
use pythonize::pythonize;

#[derive(Serialize, Deserialize)]
struct Sample {
    foo: String,
    bar: Option<usize>
}

Python::with_gil(|py| -> PyResult<()> {
    let sample = Sample {
        foo: "foo".to_string(),
        bar: None
    };

    let obj = pythonize(py, &sample)?;

    println!("{}", obj.as_ref(py).repr());
})

// XXX: depythonize is not yet implemented!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages