Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated python example #1361

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" and "pip install -r requirements.in"
fsouza marked this conversation as resolved.
Show resolved Hide resolved
# 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
Expand Down