A tool for provide format and serialize support to json, xml, form data and query string.
Project description
PyDeclares
This library provides a simple API for encoding and decoding declared classes to and from JSON, XML, FORM-DATA or QueryString.
It's very easy to get started.
Quickstart
pip install pydeclares
from pydeclares import var, Declared
class Person(Declared):
name = var(str)
age = var(int)
# decode json string
data = '{"name": "Tom", "age": 18}'
person = Person.from_json(data)
assert person.name == "Tom"
assert person.age == 18
# you can encode to xml after decode json string
result = person.to_xml()
assert result == '<person><name>Tom</name><age>18</age></person>'
# or form-data
result = person.to_form_data()
assert result == "name=Tom&age=18"
# or query string
person = Person(name="tom@a", age=18)
result = person.to_query_string()
assert result == "name=tom%40a&age=18"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydeclares-1.0.2.tar.gz
(18.9 kB
view hashes)
Built Distribution
pydeclares-1.0.2-py3-none-any.whl
(23.6 kB
view hashes)
Close
Hashes for pydeclares-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 056c50e03af5d9820d8ac6fa7bcceb40de0f847ec62256b13a4c2a009d6cbdda |
|
MD5 | eb49462953717e09766a3cf520396370 |
|
BLAKE2b-256 | f39babe4863b33993eff3eb99914c29779263b703c6c4499dee25a6bc3c2611b |