Yes, instead of passing the options as command line arguments you can set them in the code.
After the following line:
pipeline_options = PipelineOptions(pipeline_args)
you can add the following 2 lines:
google_cloud_options = pipeline_options.view_as(GoogleCloudOptions)
google_cloud_options.temp_location = 'gs://tests_tmp/tmp'
You have to treat the options as GoogleCloudOptions, as PipelineOptions does not have temp_location attribute.
Here is the relevant part in the doc:
https://beam.apache.org/get-started/wordcount-example/#creating-the-pipeline