diff --git a/examples/python/python.py b/examples/python/python.py index e62cc05a5b..e1743d9997 100644 --- a/examples/python/python.py +++ b/examples/python/python.py @@ -2,14 +2,36 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +# How to run this example +# 1 - Build the docker image by running the command "docker build -t fsouza/fake-gcs-server ." +# 2 - Start the docker container: "docker run -d --name fake-gcs-server -p 4443:4443 -v ${PWD}/examples/data:/data fsouza/fake-gcs-server -scheme http" +# 3 - Check if it's working by running: "curl http://0.0.0.0:4443/storage/v1/b" +# 4 - Create a python virtual enviroment (Ex: python -m .venv venv) +# 5 - Source the env (source .venv/bin/activate) +# 7 - Go to the following directory examples/python: (cd examples/python) +# 6 - Install requirements: "pip install -r requirements.txt" +# 7 - Run this script + +# For additional info on how to run this example or setup the docker container check the +# run script "ci/run-python-example.sh" + import tempfile +import os from google.auth.credentials import AnonymousCredentials from google.cloud import storage +# This endpoint assumes that you are using the default port 4443 from the container. +# If you are using a different port, please set the environment variable STORAGE_EMULATOR_HOST. +os.environ.setdefault("STORAGE_EMULATOR_HOST", "http://localhost:4443") + + client = storage.Client( credentials=AnonymousCredentials(), project="test", + # Alternatively instead of using the global env STORAGE_EMULATOR_HOST. You can define it here. + # This will set this client object to point to the local google cloud storage. + # client_options={"api_endpoint": "http://localhost:4443"}, ) # List the Buckets