Change the default processor version
Stay organized with collections
Save and categorize content based on your preferences.
A processor's default version specifies the version that is used to process documents when you don't specify a specific version. When you create a processor, the initial default version is the latest version in the stable channel.
If you change the default version, incoming requests are processed using the newly selected version. If you change the default version while the processor is in the middle of a request, the request will continue to use the previously selected version.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThe default processor version is used to process documents when no specific version is indicated.\u003c/p\u003e\n"],["\u003cp\u003eUpon creation, a processor's initial default version is the most recent stable channel version.\u003c/p\u003e\n"],["\u003cp\u003eChanging the default processor version means that all future requests will be processed using the newly selected version.\u003c/p\u003e\n"],["\u003cp\u003eIf a request is being processed and the default version is changed, that ongoing request will complete with the previously selected version.\u003c/p\u003e\n"]]],[],null,["# Change the default processor version\n\nA processor's default version specifies the version that is used to process documents when you don't specify a specific version. When you create a processor, the initial default version is the latest version in the stable channel.\n\nIf you change the default version, incoming requests are processed using the newly selected version. If you change the default version while the processor is in the middle of a request, the request will continue to use the previously selected version.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Managing processor versions](/document-ai/docs/manage-processor-versions)\n\nCode sample\n-----------\n\n### Python\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.api_core.exceptions import NotFound\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_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample\n # processor_version_id = 'YOUR_PROCESSOR_VERSION_ID'\n\n\n def set_default_processor_version_sample(\n project_id: str, location: str, processor_id: str, processor_version_id: 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 processor\n # e.g.: projects/project_id/locations/location/processors/processor_id\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_processor_path(project_id, location, processor_id)\n\n # The full resource name of the processor version\n # e.g.: projects/project_id/locations/location/processors/processor_id/processorVersions/processor_version_id\n processor_version = 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_processor_version_path(\n project_id, location, processor_id, processor_version_id\n )\n\n request = documentai.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.types.SetDefaultProcessorVersionRequest.html(\n processor=processor, default_processor_version=processor_version\n )\n\n # Make SetDefaultProcessorVersion request\n try:\n operation = 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_set_default_processor_version(request)\n # Print operation details\n print(operation.operation.name)\n # Wait for operation to complete\n operation.result()\n except NotFound as e:\n print(e.message)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=documentai)."]]