An example PySpark job to sort the contents of a text file in Cloud Storage.

## Code sample

### Python


Before trying this sample, follow the Python setup instructions in the
[Managed Service for Apache Spark quickstart using
client libraries](https://docs.cloud.google.com/managed-spark/docs/quickstarts/create-cluster-client-libraries).


For more information, see the
[Managed Service for Apache Spark Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/dataproc/latest).


To authenticate to Managed Service for Apache Spark, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```python
import pyspark

sc = pyspark.SparkContext()
rdd = sc.textFile("gs://path-to-your-GCS-file")
print(sorted(rdd.collect()))
```

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples.md.txt?product=dataproc).