Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment générer une bibliothèque cliente à partir de votre API backend Python (correspondant au code exécuté sur le serveur). Toute application Java ou Android peut utiliser cette bibliothèque pour appeler l'API.
Téléchargez la bibliothèque et les outils Cloud Endpoints Frameworks dans le répertoire de votre application, comme indiqué dans la section Premiers pas avec Endpoints Frameworks.
Assurez-vous que le code de votre API est correctement décoré avec le code Frameworks attendu.
où main est la classe contenant votre API, et EchoApi est le nom de cette API.
Patientez le temps que l'outil génère la bibliothèque. Si l'opération aboutit, l'outil affiche un message semblable à celui-ci :
API client library written to ./echo-v1.zip
Décompressez le fichier à l'aide de l'utilitaire unzip ou d'un autre utilitaire de désarchivage compatible ZIP :
unzip./echo-v1-java.zip
Changez de répertoire :
cdecho
Créez la bibliothèque cliente :
gradlebuild
La sortie se trouve dans le répertoire build/libs. Le nom exact du fichier dépendra de la version du client, Le résultat est semblable à echo-v1-1.23.0-SNAPSHOT.jar.
Ajoutez le fichier JAR de la bibliothèque cliente à votre application.
Répétez ces étapes chaque fois que vous modifiez le code de l'API.
Étape suivante
Pour obtenir plus d'informations et découvrir un exemple de code montrant comment accéder à une API backend à partir d'un client Python, consultez la page Accéder aux API backend à partir des clients Python.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis guide explains how to generate a Java client library from a Python backend API, which enables Java and Android applications to interact with the API.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves using the Endpoints Frameworks command-line tool to create a Gradle client bundle from your API code, using the class and name of your API.\u003c/p\u003e\n"],["\u003cp\u003eOnce the client library is generated as a ZIP file, it must be unzipped, built using Gradle, and the resulting JAR file added to the Java or Android application.\u003c/p\u003e\n"],["\u003cp\u003eIt is important to repeat the library generation process whenever modifications are made to the backend API code to ensure the client library remains in sync with the server code.\u003c/p\u003e\n"],["\u003cp\u003eFor generating iOS clients for your API, Google APIs Objective-C Client Library for REST APIs is recommended, it is also possible to access backend API from a Python client.\u003c/p\u003e\n"]]],[],null,["# Generating a client library\n\nThis page describes how to generate a client library from your Python backend\nAPI (the code that runs on the server). Any Java or Android app can use this\nlibrary to call the API.\n\nTo create iOS clients for your API, we recommend that you use\n[Google APIs Objective-C Client Library for REST APIs](https://github.com/google/google-api-objectivec-client-for-rest/wiki).\n\nBefore you begin\n----------------\n\n- Download the Cloud Endpoints Frameworks library and tools into your app directory as described in [Getting started with Endpoints Frameworks](/endpoints/docs/frameworks/python/quickstart-frameworks-python).\n- Make sure you have properly [decorated](/endpoints/docs/frameworks/python/create_api) your API code with the expected frameworks code.\n\nGenerating the client library\n-----------------------------\n\nThe following instructions demonstrate how to use the\nEndpoints Frameworks\n[command-line\ntool](/endpoints/docs/frameworks/python/endpoints_tool) to generate a Gradle client bundle from the sample code from\n[Getting started with Cloud Endpoints](/endpoints/docs/frameworks/python/quickstart-frameworks-python).\n\nTo generate a client library:\n\n1. Change directory to the directory containing your API `app.yaml` file and\n API classes.\n\n2. Run the Endpoints command-line tool similar to the following:\n\n python lib/endpoints/endpointscfg.py get_client_lib java -bs gradle main.EchoApi\n\n where `main` is the class containing your API and `EchoApi` is your API name.\n\n Wait for the tool to generate the library; on success the tool displays a\n message similar to this one: \n\n ```\n API client library written to ./echo-v1.zip\n ```\n3. Unzip the file using the unzip utility, or use another ZIP-compatible\n unarchiving utility:\n\n unzip ./echo-v1-java.zip\n\n4. Change directory:\n\n cd echo\n\n5. Build the client library:\n\n gradle build\n\n The output is in the `build/libs` directory. The exact filename depends\n on the version of the client. It is similar to\n `echo-v1-1.23.0-SNAPSHOT.jar`.\n6. Add the client library JAR to your app.\n\n7. Repeat these steps every time you modify your API code.\n\nWhat's next\n-----------\n\nFor information and sample code showing how to access a backend API from a\nPython client, see\n[Accessing backend APIs from Python clients](/endpoints/docs/frameworks/python/access_from_python)."]]