Skip to content

Allows easy transfer of python types between brython and a python server.

License

Notifications You must be signed in to change notification settings

CplBDJ/brython_serializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

serializer

Made for transferring data between brython and a python webserver.

  1. An issue with JSON is it can't serialize python's datetime classes very well. YAML doesn't play well with brython.

  2. I needed a way to send datetime.date and datetime.time to the client. This serializer might not be the best thing for this, but it does what is needed.

  3. I also send quite a bit of data from the server that is has multiple reused strings and numbers, this was written to assist in making the transfer time smaller.

  4. Any python structure, nested or not can be passed.

  5. It does use json under the hood to facilitate the transferring of the data between server and client.

You can pip install ujson if you want the server to encode/decode faster.

from datetime import date
import serializer
serialized = serializer.dump(date.today())
# '{"&0": {"int": 2021}, "&1": {"int": 2}, "&2": {"int": 25}, "&3": {"tuple": ["&0", "&1", "&2"]}, "date": "&3"}'
serialized.loads(serialized)
# datetime.date(2021, 2, 25)

Serializable python types

type comment
bytes
str
int
float
dict
list
tuple
set
datetime
date
time
Decimal Some values transfer poorly.
None
True
False

About

Allows easy transfer of python types between brython and a python server.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages