Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
ponytailer committed Oct 8, 2024
1 parent 64076d7 commit 8468972
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
17 changes: 10 additions & 7 deletions example/use_config_to_init.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from example.protocol import BookProtocol, Book
from pydantic_client import PydanticClient, ClientConfig
from pydantic_client.clients import RequestsClient
from example.protocol import BookProtocol, Book, AuthorProtocol, Author
from pydantic_client import pydantic_client_factory, ClientConfig

if __name__ == "__main__":
cfg = ClientConfig(
client_type="requests",
base_url="https://example.com/api"
)
client = PydanticClient(cfg) \
.bind_client(RequestsClient) \
.bind_protocol(BookProtocol) \
.build()

pydantic_client_factory.register(cfg)(BookProtocol)
pydantic_client_factory.register(cfg)(AuthorProtocol)

client = pydantic_client_factory.get_client(BookProtocol)
book: Book = client.get_book(1, "name")

author_client = pydantic_client_factory.get_client(AuthorProtocol)
author: Author = author_client.get_author()
12 changes: 0 additions & 12 deletions example/use_factory.py

This file was deleted.

11 changes: 0 additions & 11 deletions example/use_toml_to_init.py

This file was deleted.

0 comments on commit 8468972

Please sign in to comment.