pieces-app / pieces-os-client-sdk-for-python

The Pieces OS Client SDK is a powerful code engine package designed for writing applications on top of Pieces OS.
MIT License
26 stars 14 forks source link

Convert the config from a dict to a typed object #36

Closed jimbobbennett closed 1 month ago

jimbobbennett commented 2 months ago

At the moment the client is configured by passing a dictionary. This is not strongly typed and easy to make mistakes, as well as not being pythonic. We should replace this with an object with named fields, and separate the host from the port.

pieces_client = PiecesClient(config={'host': f'http://localhost:{port}'})

becomes

client_config = Config(host = 'localhost', port=port)
pieces_client - PiecesClient(config=client_config)

In addition, the host and port should be optional (same with the config), and if not set we detect the OS and use localhost with the relevant port. This way you can do the following:

pieces_client - PiecesClient()

And it will use localhost:1000 for macOS/windows, and localhost:5323 on Linux. Abstracting boilerplate logic like this is one of the benefits of a good SDK.