Skip to content

Instantly share code, notes, and snippets.

Forked from gordcorp/
Created August 16, 2023 06:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Empty and reseed GeoServer GeoWebCache
import requests
class GeoWebCacheService(object):
"""Class to communicate with the geowebcache api.
Api doco here:
_url = None
_username = None
_password = None
def __init__(self, url, username, password):
self._url = url
self._username = username
self._password = password
def _get_seed_url(self, layer):
if layer != None:
layer = urllib.parse.quote(layer)
url = urllib.parse.urljoin(self._url, "seed/%s.json" % layer)
url = urllib.parse.urljoin(self._url, "seed.json")
return url
def get_tasks(self, layer=None):
url = self._get_seed_url(layer)
r = requests.get(url, auth=(self._username, self._password))
j = r.json()
return j["long-array-array"]
def empty(self, layer):
"""Empty the cache for this layer.
url = self._get_seed_url(layer)
# There isn't a simple Empty call in the API, so instead I'm doing a separate truncate on each of
# the caches that are defined by default in geoserver.
grid_set_ids = ["EPSG:900913", "EPSG:4326"]
formats = ["image/jpeg", "image/png"]
for grid_set_id in grid_set_ids:
for fmt in formats:
data = {
"seedRequest": {
}, auth=(self._username, self._password), json=data)
# With help from
def seed(self, layer):
"""Start seeding the given layer
url = self._get_seed_url(layer)
# Seed with the national map parameters
data = {
"seedRequest": {
}, auth=(self._username, self._password), json=data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment