[
https://issues.apache.org/jira/browse/SOLR-16835?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17728970#comment-17728970
]
Jason Gerlowski commented on SOLR-16835:
----------------------------------------
I've opened a PR [here|https://github.com/apache/solr/pull/1681] that uses the
"[openapi-generator gradle
plugin|https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc]"
to read our OpenAPI spec and generate Python client from it. The integration
itself is relatively simple - just a few lines in {{solr/core/build.gradle}}.
But there's a lot to review in terms of looking at the overall shape of the
generated client and deciding whether/how it should be improved.
----
*Generation/Setup Instructions*
After checking out the
[branch|https://github.com/gerlowskija/solr/tree/SOLR-16835-python-client-generation],
follow the steps below to generate and start using the Python client. All but
the first and last of these steps are really about setting up your Python
environment: folks already set up to run Python or familiar with the process
can skip them. (I've included them as they were new to me - and I suspect to
many others here since we're not really a Python project.)
# Run {{./gradlew openApiGenerate}} to create the Python client in
{{solr/core/build/generated/python/}}
# {{cd solr/core/build/generated/python/}}
# Install [Python
Virtualenv|https://virtualenv.pypa.io/en/latest/installation.html] and Python3
as necessary
# Create a virtual environment: {{python3 -m venv venv}}
# Activate virtual environment: {{source venv/bin/activate}}
# Install some necessary packages (TODO Why doesn't setup.py below handle
these?): {{pip install python-dateutil urllib3}}
# Install the Solr Python client! {{python setup.py install --user}}
After installation, users would be able to use the client with code similar to
the example below:
{code:python}
import solr
from pprint import pprint
from solr.api import collection_api
from solr.model.create_collection_request_body import
CreateCollectionRequestBody
configuration = solr.Configuration(host = "http://localhost:8983/api")
with solr.ApiClient(configuration) as api_client:
api_instance = collection_api.CollectionApi(api_client)
create_params = CreateCollectionRequestBody(
name = "mycollname",
num_shards = 1
)
try:
api_response =
api_instance.create_collection(create_collection_request_body = create_params)
pprint(api_response)
except solr.ApiException as e:
print("Exception when calling CollectionApi->create_collection: %s\n" %
e)
{code}
> Generate Python bindings from OpenAPI spec
> ------------------------------------------
>
> Key: SOLR-16835
> URL: https://issues.apache.org/jira/browse/SOLR-16835
> Project: Solr
> Issue Type: New Feature
> Security Level: Public(Default Security Level. Issues are Public)
> Components: v2 API
> Affects Versions: main (10.0)
> Reporter: Jason Gerlowski
> Priority: Minor
> Labels: client
> Time Spent: 20m
> Remaining Estimate: 0h
>
> SOLR-16346 added support to Solr's build to generate an "OpenAPI spec" file
> describing our v2 API. But currently, this spec file isn't actually used by
> Solr in any way.
> Spec files can be used for a variety of purposes, including to generate
> client bindings in a variety of languages.
> OpenAPI supports client-generation in many languages. Among these Python is
> particularly promising due to the popularity of the language itself and of
> the 3rd-party "pysolr" client.
> (It's also an appealing starting-point from a development perspective, as
> it's "green field" and therefore unconstrained by compatibility concerns as
> the Java binding in SOLR-16825 is.)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]