Créer un outil de traitement
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Crée un processeur.
En savoir plus
Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les articles suivants :
Exemple de code
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.
[[["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"]],[],[[["\u003cp\u003eThis content demonstrates how to create a new processor within Google Cloud's Document AI using the Python API.\u003c/p\u003e\n"],["\u003cp\u003eThe code sample provided shows how to initialize the Document AI client, configure the processor's location and name, and then create the processor.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Document AI requires setting up Application Default Credentials, and instructions are provided for setting this up in a local development environment.\u003c/p\u003e\n"],["\u003cp\u003eTo explore the available processor types or to filter other Google Cloud product samples, you can utilize the Google Cloud sample browser or the \u003ccode\u003efetch_processor_types\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe location of the processor may necessitate setting the api_endpoint when initializing the client.\u003c/p\u003e\n"]]],[],null,["Creates a new processor\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Creating and managing processors](/document-ai/docs/create-processor)\n\nCode sample \n\nPython\n\n\nFor more information, see the\n[Document AI Python API\nreference documentation](/python/docs/reference/documentai/latest).\n\n\nTo authenticate to Document AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n from google.api_core.client_options import ClientOptions\n from google.cloud import documentai # type: ignore\n\n # TODO(developer): Uncomment these variables before running the sample.\n # project_id = 'YOUR_PROJECT_ID'\n # location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu'\n # processor_display_name = 'YOUR_PROCESSOR_DISPLAY_NAME' # Must be unique per project, e.g.: 'My Processor'\n # processor_type = 'YOUR_PROCESSOR_TYPE' # Use fetch_processor_types to get available processor types\n\n\n def create_processor_sample(\n project_id: str, location: str, processor_display_name: str, processor_type: str\n ) -\u003e None:\n # You must set the api_endpoint if you use a location other than 'us'.\n opts = ClientOptions(api_endpoint=f\"{location}-documentai.googleapis.com\")\n\n client = documentai.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html(client_options=opts)\n\n # The full resource name of the location\n # e.g.: projects/project_id/locations/location\n parent = client.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html#google_cloud_documentai_v1_services_document_processor_service_DocumentProcessorServiceClient_common_location_path(project_id, location)\n\n # Create a processor\n processor = client.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html#google_cloud_documentai_v1_services_document_processor_service_DocumentProcessorServiceClient_create_processor(\n parent=parent,\n processor=documentai.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.types.Processor.html(\n display_name=processor_display_name, type_=processor_type\n ),\n )\n\n # Print the processor information\n print(f\"Processor Name: {processor.name}\")\n print(f\"Processor Display Name: {processor.display_name}\")\n print(f\"Processor Type: {processor.type_}\")\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=documentai)."]]