Skip to content

pyserde extension for (de)serializing datetime.timedelta in ISO 8601 duration format

License

Notifications You must be signed in to change notification settings

yukinarit/pyserde-timedelta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyserde extension for datetime.timedelta.

import serde_timedelta
from serde import serde
from serde.json import to_json, from_json
from datetime import timedelta

# Initialize serde_timedelta extension.
serde_timedelta.init()


@serde
class Foo:
    a: timedelta


f = Foo(timedelta(hours=10))
json = to_json(f)
print(json)                  # Prints {"a":"PT10H"}
print(from_json(Foo, json))  # Prints Foo(a=datetime.timedelta(seconds=36000))

About

pyserde extension for (de)serializing datetime.timedelta in ISO 8601 duration format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages