CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-josepy

tessl install tessl/pypi-josepy@2.1.0

JOSE protocol implementation in Python with support for JSON Web Algorithms, Keys, and Signatures

Agent Success

Agent success rate when using this tile

73%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.16x

Baseline

Agent success rate without this tile

63%

task.mdevals/scenario-10/

Typed Message Dispatch

Define JSON-serializable message models that use a type field to select the correct subclass when deserializing, while safely handling unknown or missing types. The type value error maps to ErrorMessage and info maps to InfoMessage, and that field must always be present in serialized output.

Capabilities

Type-based deserialization

  • Given payload {"type": "error", "content": "Failed", "code": 500, "detail": "DB down"}, Message.from_json returns an ErrorMessage instance with matching attributes. @test
  • If payload uses an unregistered type value, Message.from_json raises a descriptive exception mentioning that type value. @test
  • If payload omits the type field, Message.from_json raises a descriptive exception about the missing type field. @test

Serialization roundtrip

  • Serializing an InfoMessage with to_json and deserializing it with Message.from_json preserves the type of info and subclass-specific fields such as level and content. @test

Implementation

@generates

API

from typing import Any, Dict

class Message:
    message_type: str

    @classmethod
    def from_json(cls, payload: Dict[str, Any]) -> "Message":
        ...

    def to_json(self) -> Dict[str, Any]:
        ...

class ErrorMessage(Message):
    message_type: str = "error"
    content: str
    code: int
    detail: str

class InfoMessage(Message):
    message_type: str = "info"
    content: str
    level: str

Dependencies { .dependencies }

josepy { .dependency }

Provides declarative JSON field definitions and type-based object dispatching utilities.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/josepy@2.1.x
tile.json