typesense / typesense-python

Python client for Typesense: https://github.com/typesense/typesense
Apache License 2.0
177 stars 38 forks source link

Allow building Node from a URL #43

Closed CodeSandwich closed 11 months ago

CodeSandwich commented 1 year ago

Description

To create an instance of Node the user need to provide a host, a port, a path and a protocol. These parameters are then used to build the URL in function url, which seems to be the only usage of these 4 parameters.

It would be more convenient if it was possible to pass the URL directly into the Node constructor instead of breaking it up into 4 ingredients passed as separate variables. This would help downstream projects handle configuration in a more concise way. For example docsearch-scraper requires users to pass TYPESENSE_HOST, TYPESENSE_PORT and TYPESENSE_PROTOCOL, plus optionally TYPESENSE_PATH. This is inconvenient and in some cases problematic, because URLs are usually handled as strings. To pass a URL into typesense-scraper one needs to parse it and break up into components only for Node to assemble them back. If Node constructor accepted plain URLs, typesense-scraper could require just a single argument, TYPESENSE_URL.

At least in typsesense-python, the only usage for Node's URL components is for building the whole URL and for building a shortened URL consisting only of the host and the port. This shortened representation is only used for logging, it could easily switch to printing full URLs, it would even be clearer.

kishorenc commented 1 year ago

I agree, happy to accept a PR for this.

CodeSandwich commented 1 year ago

Do you think that it would be beneficial to keep the existing Node's host, port, path and protocol fields? I think not, just having a single url field should be enough, but this will be a breaking change.

kishorenc commented 1 year ago

We should not break backward compatibility so this should be an additional way to construct Node.