diff --git a/example/use_config_to_init.py b/example/use_config_to_init.py index a656765..30e7a6b 100644 --- a/example/use_config_to_init.py +++ b/example/use_config_to_init.py @@ -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() diff --git a/example/use_factory.py b/example/use_factory.py deleted file mode 100644 index d70406b..0000000 --- a/example/use_factory.py +++ /dev/null @@ -1,12 +0,0 @@ -from example.protocol import AuthorProtocol, BookProtocol, Book, Author -from pydantic_client import PydanticClientFactory -from pydantic_client.clients import RequestsClient, HttpxClient - -if __name__ == '__main__': - factory = PydanticClientFactory.from_toml("pydantic_client.toml") \ - .register_client("book_client", RequestsClient, BookProtocol) \ - .register_client("author_client", HttpxClient, AuthorProtocol) \ - .build() - - book: Book = factory.get_client(BookProtocol).get_book(1, "name") - author: Author = factory.get_client(AuthorProtocol).get_author() diff --git a/example/use_toml_to_init.py b/example/use_toml_to_init.py deleted file mode 100644 index acca40b..0000000 --- a/example/use_toml_to_init.py +++ /dev/null @@ -1,11 +0,0 @@ -from example.protocol import BookProtocol, Book -from pydantic_client import PydanticClient -from pydantic_client.clients import RequestsClient - -if __name__ == "__main__": - client = PydanticClient.from_toml("config.toml") \ - .bind_client(RequestsClient) \ - .bind_protocol(BookProtocol) \ - .build() - - book: Book = client.get_book(1, "name")