Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dataclasses for response #2

Open
baffelli opened this issue Jul 21, 2023 · 2 comments
Open

Use dataclasses for response #2

baffelli opened this issue Jul 21, 2023 · 2 comments

Comments

@baffelli
Copy link
Member

Instead of directly accessing json, you could define a few helper dataclasses or pydantic models:

pub_key = response.json()["public"]

@edoardob90
Copy link
Member

You're suggesting something like the following?

from pydantic import BaseModel

class KeyResponse(BaseModel):
    public: str
    private: str

response_model = KeyResponse.model_validate(response.content.decode())
pub_key = response_model.public
priv_key = response_model.private

@baffelli
Copy link
Member Author

Yes, correct. I think it's a bit safer and slightly more ergonomic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants