Current collected state Current
Observed since 20 Oct, 16:39 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
a3json-struct can describe JSON structs using class-based syntax.
English | 简体中文
a3json-struct can describe JSON structs using class-based syntax.pip install a3json-struct
from datetime import datetime
from a3json_struct import struct
class Comment(struct.JsonStruct):
content = struct.CharField()
post_time = struct.DateTimeField()
class Video(struct.JsonStruct):
id = struct.IntegerField(verbose_name='video id')
url = struct.CharField()
title = struct.CharField(min_length=5, max_length=30)
description = struct.CharField()
score = struct.DecimalField()
view_count = struct.IntegerField(default=0)
tag_list = struct.ListField(element_field=struct.CharField(min_length=2, max_length=8), required=False)
comment_list = struct.ListField(element_field=struct.ObjectField(obj_kls=Comment))
if __name__ == '__main__':
comment = Comment()
comment.content = "content"
comment.post_time = "2023-09-10 20:32"
video = Video()
video.id = 12345
video.url = "https://xxx.xxx/12345.mp4"
video.title = "video title"
video.description = "video description"
video.score = '2.3'
video.comment_list = [
comment, # It can be an object instance
{"content": "content", "post_time": datetime.now()} # or a dictionary
]
video.full_clean() # Validate data (this step can be omitted if using to_json or to_bson)
assert isinstance(video.to_json()["comment_list"][0]["post_time"], str)
assert isinstance(video.to_bson()["comment_list"][0]["post_time"], datetime)
openapi_schema = Video.generate_openapi_schema()
print(openapi_schema)
meta_schema = Video.generate_meta_schema()
RestoredVideo = struct.JsonStruct.build_variant_from_meta_schema(meta_schema, "RestoredVideo")
assert RestoredVideo.generate_meta_schema() == meta_schema
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.3.0 | 21 Mar 2025 | 1 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 16:39 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:b0dc0adb3d03a6e2fa3326feadab2a41ee23ad56b18312a4e4435270ae52d231