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-1/

Contact Profile JSON Mapper

Model a contact profile object that maps attribute names to specific JSON keys, fills in defaults when fields are absent, and omits optional values when they are empty. Attribute to JSON key mapping must be: username -> user, email -> contact_email, timezone -> tz, phone -> phone, tags -> labels, and marketing_opt_in -> marketing_opt_in.

Capabilities

Defaults applied on load

  • Parsing JSON missing tz and marketing_opt_in yields a profile with timezone "UTC" and marketing_opt_in False; serializing the result with json_dumps includes those defaults along with the provided user and contact_email values. @test

Omit optional empties

  • When phone is null and labels array is empty on the Python object, both json_dumps and to_partial_json omit phone and labels entirely while still including required fields and the defaulted timezone. @test

JSON key mapping round-trip

  • Starting from a dict {"user": "ana", "contact_email": "ana@example.com", "phone": "+123", "tz": "Europe/Paris", "labels": ["vip"]}, loading to a profile and converting back to a dict via the JSON serialization API preserves all values and uses the same JSON keys. @test

Implementation

@generates

API

class ContactProfile:
    def __init__(self, username: str, email: str, timezone: str = "UTC", phone: Optional[str] = None, tags: Optional[list[str]] = None, marketing_opt_in: bool = False): ...
    @classmethod
    def from_json(cls, jobj: Any) -> "ContactProfile": ...
    @classmethod
    def json_loads(cls, json_string: str) -> "ContactProfile": ...
    def to_partial_json(self) -> dict: ...
    def json_dumps(self, **kwargs) -> str: ...

Dependencies { .dependencies }

josepy { .dependency }

Provides declarative JSON object mapping with field defaults and omission of empty values during serialization.

Version

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