Skip to content

GeoServer

Bases: Base

GeoServer Client for Python. Use this class to interact with a GeoServer instance.

Note

This class implements most of the GeoServer REST API endpoints. You can follow the official GeoServer REST API documentation here.

Parameters:

Name Type Description Default
service_url str

The URL of the GeoServer instance.

'http://localhost:8080/geoserver'
username Optional[str]

The username to authenticate with the GeoServer instance.

None
password Optional[str]

The password to authenticate with the GeoServer instance.

None
headers Optional[Dict[str, Any]]

The headers to be included in the requests.

None
cookies Optional[Dict[str, Any]]

The cookies to be included in the requests.

None
auth Optional[AuthBase]

The authentication to be included in the requests.

None
allow_redirects bool

A boolean indicating whether or not the requests should follow redirects.

True
proxies Any

The proxies to be included in the requests.

None
verify bool

A boolean indicating whether or not the SSL certificates should be verified.

True
cert Optional[str]

The certificate to be included in the requests.

None
timeout Optional[Timeout]

How many seconds to wait for the server, either a single value or a (connect, read) tuple. Waits forever by default. Set the timeout attribute to change it, e.g. before a long upload.

None
session Optional[Session]

The requests.Session used to send the requests, e.g. to configure retries. A new session is created by default.

None
Example
from geoserver import GeoServer

geoserver = GeoServer(
    service_url="http://localhost:8080/geoserver",
    username="admin",
    password="geoserver",
    timeout=30,
)

The client reuses its connections across requests. Use it as a context manager to close them when done:

with GeoServer("http://localhost:8080/geoserver", username="admin", password="geoserver") as geoserver:
    geoserver.get_workspaces()

To retry failed requests, pass a session with a retry policy:

import requests
from requests.adapters import HTTPAdapter
from urllib3.util import Retry

session = requests.Session()
session.mount("http://", HTTPAdapter(max_retries=Retry(total=3, backoff_factor=0.5)))
geoserver = GeoServer("http://localhost:8080/geoserver", username="admin", password="geoserver", session=session)
Source code in geoserver/base.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    service_url: str = "http://localhost:8080/geoserver",
    username: Optional[str] = None,
    password: Optional[str] = None,
    headers: Optional[Dict[str, Any]] = None,
    cookies: Optional[Dict[str, Any]] = None,
    auth: Optional[AuthBase] = None,
    allow_redirects: bool = True,
    proxies: Any = None,
    verify: bool = True,
    cert: Optional[str] = None,
    timeout: Optional[Timeout] = None,
    session: Optional[requests.Session] = None,
):
    if auth is None and username is not None and password is not None:
        auth = HTTPBasicAuth(username, password)

    self.service_url = service_url.rstrip("/")
    self.auth = auth
    self.headers = headers or {}
    self.cookies = cookies or {}
    self.allow_redirects = allow_redirects
    self.proxies = proxies or {}
    self.verify = verify
    self.cert = cert
    self.timeout = timeout
    self.session = session if session is not None else requests.Session()

get_manifest

get_manifest(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_manifest(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_manifest(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves the manifest of the GeoServer instance, in JSON format.

Parameters:

Name Type Description Default
manifest Optional[str]

Optional. The manifest parameter is used to filter over resulting resource (manifest) names attribute using Java regular expressions. Defaults to None.

None
key Optional[str]

Optional. Only return manifest entries with this key in their properties. It can be optionally combined with the value parameter. Defaults to None.

None
value Optional[str]

Optional. Only return manifest entries that have this value for the provided key parameter. Defaults to None.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The manifest of the GeoServer instance.

Example

To get the manifest of the GeoServer instance, use the following code:

geoserver.get_manifest()
Source code in geoserver/geoserver.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def get_manifest(
    self,
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Retrieves the manifest of the GeoServer instance, in JSON format.

    Args:
        manifest: Optional. The manifest parameter is used to filter over resulting resource (manifest) names attribute using Java regular expressions. Defaults to None.
        key: Optional. Only return manifest entries with this key in their properties. It can be optionally combined with the value parameter. Defaults to None.
        value: Optional. Only return manifest entries that have this value for the provided key parameter. Defaults to None.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The manifest of the GeoServer instance.

    Example:
        To get the manifest of the GeoServer instance, use the following code:

        ```python
        geoserver.get_manifest()
        ```

    """
    url = f"{self.service_url}/rest/about/manifest.{format}"
    params = dict(manifest=manifest, key=key, value=value)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

get_version

get_version(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_version(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_version(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Shows only the details for the high-level components: GeoServer, GeoTools, and GeoWebCache

Parameters:

Name Type Description Default
manifest Optional[str]

Optional. The manifest parameter is used to filter over resulting resource (manifest) names attribute using Java regular expressions. Defaults to None.

None
key Optional[str]

Optional. Only return manifest entries with this key in their properties. It can be optionally combined with the value parameter. Defaults to None.

None
value Optional[str]

Optional. Only return manifest entries that have this value for the provided key parameter. Defaults to None.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The version of the GeoServer instance.

Example

To get the version of the GeoServer instance, use the following code:

geoserver.get_version()
Source code in geoserver/geoserver.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def get_version(
    self,
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Shows only the details for the high-level components: GeoServer, GeoTools, and GeoWebCache

    Args:
        manifest: Optional. The manifest parameter is used to filter over resulting resource (manifest) names attribute using Java regular expressions. Defaults to None.
        key: Optional. Only return manifest entries with this key in their properties. It can be optionally combined with the value parameter. Defaults to None.
        value: Optional. Only return manifest entries that have this value for the provided key parameter. Defaults to None.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The version of the GeoServer instance.

    Example:
        To get the version of the GeoServer instance, use the following code:

        ```python
        geoserver.get_version()
        ```
    """
    url = f"{self.service_url}/rest/about/version.{format}"
    params = dict(manifest=manifest, key=key, value=value)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

get_status

get_status(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_status(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_status(
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Shows the status details of all installed and configured modules. Status details always include human readable name, and module name. Optional details include version, availability, status message, and links to documentation.

Parameters:

Name Type Description Default
manifest Optional[str]

Optional. The manifest parameter is used to filter over resulting resource (manifest) names attribute using Java regular expressions. Defaults to None.

None
key Optional[str]

Optional. Only return manifest entries with this key in their properties. It can be optionally combined with the value parameter. Defaults to None.

None
value Optional[str]

Optional. Only return manifest entries that have this value for the provided key parameter. Defaults to None.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The version of the GeoServer instance.

Example

To get the status of the GeoServer instance, use the following code:

geoserver.get_status()
Source code in geoserver/geoserver.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
def get_status(
    self,
    *,
    manifest: Optional[str] = None,
    key: Optional[str] = None,
    value: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Shows the status details of all installed and configured modules. Status details always include human readable name, and module name. Optional details include version, availability, status message, and links to documentation.

    Args:
        manifest: Optional. The manifest parameter is used to filter over resulting resource (manifest) names attribute using Java regular expressions. Defaults to None.
        key: Optional. Only return manifest entries with this key in their properties. It can be optionally combined with the value parameter. Defaults to None.
        value: Optional. Only return manifest entries that have this value for the provided key parameter. Defaults to None.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The version of the GeoServer instance.

    Example:
        To get the status of the GeoServer instance, use the following code:

        ```python
        geoserver.get_status()
        ```
    """
    url = f"{self.service_url}/rest/about/status.{format}"
    params = dict(manifest=manifest, key=key, value=value)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

get_system_status

get_system_status(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_system_status(*, format: Literal['xml']) -> str
get_system_status(*, format: Literal['html']) -> str
get_system_status(
    *, format: Literal["json", "xml", "html"] = "json"
) -> Union[str, Dict[str, Any]]

Returns a list of system-level information. Major operating systems (Linux, Windows and MacOX) are supported out of the box.

Returns:

Type Description
Union[str, Dict[str, Any]]

The system status of the GeoServer instance.

Example

To get the system status of the GeoServer instance, use the following code:

geoserver.get_system_status()
Source code in geoserver/geoserver.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def get_system_status(self, *, format: Literal["json", "xml", "html"] = "json") -> Union[str, Dict[str, Any]]:
    """Returns a list of system-level information. Major operating systems (Linux, Windows and MacOX) are supported out of the box.

    Returns:
        The system status of the GeoServer instance.

    Example:
        To get the system status of the GeoServer instance, use the following code:

        ```python
        geoserver.get_system_status()
        ```
    """
    url = f"{self.service_url}/rest/about/system-status.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

get_data_stores

get_data_stores(
    *, workspace: str, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_data_stores(
    *, workspace: str, format: Literal["xml"]
) -> str
get_data_stores(
    *,
    workspace: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

List all data stores in workspace ws.

Parameters:

Name Type Description Default
workspace str

The name of the workspace containing the data stores.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all datastores in the workspace.

Example

To get the list of all data stores in the workspace, use the following code:

geoserver.get_data_stores(workspace="my_workspace")
Source code in geoserver/geoserver.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def get_data_stores(self, *, workspace: str, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """List all data stores in workspace ws.

    Args:
        workspace: The name of the workspace containing the data stores.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The list of all datastores in the workspace.

    Example:
        To get the list of all data stores in the workspace, use the following code:

        ```python
        geoserver.get_data_stores(workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

data_store_exists

data_store_exists(name: str, *, workspace: str) -> bool

Check if a data store exists in a workspace.

Parameters:

Name Type Description Default
name str

The name of the data store.

required
workspace str

The name of the workspace containing the data stores.

required

Returns:

Type Description
bool

True if the data store exists, False otherwise.

Example

To check if a data store exists in a workspace, use the following code:

geoserver.data_store_exists("my_data_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
def data_store_exists(self, name: str, *, workspace: str) -> bool:
    """Check if a data store exists in a workspace.

    Args:
        name: The name of the data store.
        workspace: The name of the workspace containing the data stores.

    Returns:
        True if the data store exists, False otherwise.

    Example:
        To check if a data store exists in a workspace, use the following code:

        ```python
        geoserver.data_store_exists("my_data_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}.xml"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_data_store

create_data_store(
    body: Union[str, Dict[str, Any]], *, workspace: str
) -> str

Adds a new data store to the workspace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the data store.

required
workspace str

The name of the workspace containing the data stores.

required

Returns:

Type Description
str

The data store created.

Example

To create a new data store in a workspace, use the following code:

body = """
<dataStore>
    <name>my_data_store</name>
    <connectionParameters>
        <entry key="host">localhost</entry>
        <entry key="port">5432</entry>
        <entry key="database">my_database</entry>
        <entry key="user">my_user</entry>
        <entry key="passwd">my_password</entry>
        <entry key="dbtype">postgis</entry>
    </connectionParameters>
</dataStore>
"""

geoserver.create_data_store(body, workspace="my_workspace")
Source code in geoserver/geoserver.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
def create_data_store(self, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Adds a new data store to the workspace.

    Args:
        body: The body of the request used to create the data store.
        workspace: The name of the workspace containing the data stores.

    Returns:
        The data store created.

    Example:
        To create a new data store in a workspace, use the following code:

        ```python
        body = \"\"\"
        <dataStore>
            <name>my_data_store</name>
            <connectionParameters>
                <entry key="host">localhost</entry>
                <entry key="port">5432</entry>
                <entry key="database">my_database</entry>
                <entry key="user">my_user</entry>
                <entry key="passwd">my_password</entry>
                <entry key="dbtype">postgis</entry>
            </connectionParameters>
        </dataStore>
        \"\"\"

        geoserver.create_data_store(body, workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

upload_data_store

upload_data_store(
    file: Union[str, Path, BufferedReader],
    *,
    workspace: str,
    name: Optional[str] = None,
    filename: Optional[str] = None,
    format: str = "shp",
    configure: Literal["none", "all"] = "all",
    overwrite: bool = False,
) -> str

Uploads a new or update an existing data store from a local file.

Note

The name parameter is inferred from the file name when file is a path or a file object opened from a path. It is required otherwise.

Note

The file name of the resource can be overwritten by: - Providing the filename parameter. - Using the name parameter. In this case, if the filename is not provided, the file name will be the same as the store name.

Parameters:

Name Type Description Default
file Union[str, Path, BufferedReader]

The file to upload.

required
workspace str

The name of the workspace.

required
name Optional[str]

Optional. The name of the data store.

None
filename Optional[str]

Optional. The filename parameter specifies the target file name for a file that needs to be harvested as part of a mosaic. This is important to avoid clashes and to make sure the right dimension values are available in the name for multidimensional mosaics to work. Only used if method="file".

None

Returns:

Type Description
str

Success message.

Example

To upload a new data store from a local file, use the following code:

geoserver.upload_data_store("my_shapefile.zip", workspace="my_workspace", name="my_data_store")

Or, using a buffer:

with open("my_shapefile.zip", "rb") as f:
    geoserver.upload_data_store(f, workspace="my_workspace", name="my_data_store")
Source code in geoserver/geoserver.py
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def upload_data_store(
    self,
    file: Union[str, Path, BufferedReader],
    *,
    workspace: str,
    name: Optional[str] = None,
    filename: Optional[str] = None,
    format: str = "shp",
    configure: Literal["none", "all"] = "all",
    overwrite: bool = False,
) -> str:
    """Uploads a new or update an existing data store from a local file.

    Note:
        The `name` parameter is inferred from the file name when `file` is a path or a file object opened
        from a path. It is required otherwise.

    Note:
        The file name of the resource can be overwritten by:
        - Providing the `filename` parameter.
        - Using the `name` parameter. In this case, if the `filename` is not provided,
            the file name will be the same as the store name.

    Args:
        file: The file to upload.
        workspace: The name of the workspace.
        name: Optional. The name of the data store.
        filename:  Optional. The filename parameter specifies the target file name for a file that needs to be harvested as part of a mosaic.
            This is important to avoid clashes and to make sure the right dimension values are available in the name for multidimensional mosaics to work.
            Only used if method="file".

    Returns:
        Success message.

    Example:
        To upload a new data store from a local file, use the following code:

        ```python
        geoserver.upload_data_store("my_shapefile.zip", workspace="my_workspace", name="my_data_store")
        ```

        Or, using a buffer:

        ```python
        with open("my_shapefile.zip", "rb") as f:
            geoserver.upload_data_store(f, workspace="my_workspace", name="my_data_store")
        ```
    """
    if isinstance(file, Path):
        file = file.as_posix()
    local_name = file_name(file)
    if local_name is not None:
        name = name or Path(local_name).stem
        filename = filename or f"{name}{Path(local_name).suffix}"
    if name is None:
        raise ValueError("The `name` parameter is required.")

    headers = {}
    if is_zip(file):
        headers["Content-Type"] = "application/zip"

    params = dict(filename=filename, configure=configure)
    if overwrite:
        params["update"] = "overwrite"

    if isinstance(file, str) and file.startswith(("file:", "http://", "https://")):
        method = "external" if file.startswith("file:") else "url"
        headers["Content-Type"] = "text/plain"
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}/{method}.{format}"
        self._request(method="put", url=url, data=file, params=params, headers=headers)
        return CREATED_MESSAGE

    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}/file.{format}"
    self._request(method="put", url=url, file=file, params=params, headers=headers)
    return CREATED_MESSAGE

get_data_store

get_data_store(
    name: str,
    *,
    workspace: str,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_data_store(
    name: str,
    *,
    workspace: str,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_data_store(
    name: str,
    *,
    workspace: str,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Controls a particular data store in a given workspace.

Parameters:

Name Type Description Default
name str

The name of the data store.

required
workspace str

The name of the workspace containing the data stores.

required
quiet_on_not_found bool

Optional. If true, the server will not report an error if the data store is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested data store.

Example

To get the data store, use the following code:

geoserver.get_data_store("my_data_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
def get_data_store(
    self, name: str, *, workspace: str, quiet_on_not_found: bool = False, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Controls a particular data store in a given workspace.

    Args:
        name: The name of the data store.
        workspace: The name of the workspace containing the data stores.
        quiet_on_not_found: Optional. If true, the server will not report an error if the data store is not found.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The requested data store.

    Example:
        To get the data store, use the following code:

        ```python
        geoserver.get_data_store("my_data_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}.{format}"
    params = dict(quietOnNotFound=quiet_on_not_found)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

update_data_store

update_data_store(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
) -> str

Modify a data store from a workspace.

Parameters:

Name Type Description Default
name str

The name of the data store to modify.

required
workspace str

The name of the workspace containing the data stores.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the data store.

required

Returns:

Type Description
str

Success message.

Example

To update a data store, use the following code:

body = """
<dataStore>
    <name>my_new_data_store</name>
</dataStore>
"""

geoserver.update_data_store("my_data_store", body, workspace="my_workspace")
Source code in geoserver/geoserver.py
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
def update_data_store(self, name: str, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Modify a data store from a workspace.

    Args:
        name: The name of the data store to modify.
        workspace: The name of the workspace containing the data stores.
        body: The body of the request used to modify the data store.

    Returns:
        Success message.

    Example:
        To update a data store, use the following code:

        ```python
        body = \"\"\"
        <dataStore>
            <name>my_new_data_store</name>
        </dataStore>
        \"\"\"

        geoserver.update_data_store("my_data_store", body, workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_data_store

delete_data_store(
    name: str, *, workspace: str, recurse: bool = False
) -> str

Remove data store from workspace ws.

Parameters:

Name Type Description Default
name str

The name of the data store to remove.

required
workspace str

The name of the workspace containing the data stores.

required
recurse bool

Optional. If true, all resources contained in the store are also removed. Defaults to False.

False

Returns:

Type Description
str

Success message.

Example

To delete a data store, use the following code:

geoserver.delete_data_store("my_data_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
def delete_data_store(self, name: str, *, workspace: str, recurse: bool = False) -> str:
    """Remove data store from workspace ws.

    Args:
        name: The name of the data store to remove.
        workspace: The name of the workspace containing the data stores.
        recurse: Optional. If true, all resources contained in the store are also removed. Defaults to `False`.

    Returns:
        Success message.

    Example:
        To delete a data store, use the following code:

        ```python
        geoserver.delete_data_store("my_data_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}"
    params = dict(recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

reset_data_store_caches

reset_data_store_caches(
    name: str, *, workspace: str
) -> str

Resets caches for this data store. This operation is used to force GeoServer to drop caches associated to this data store, and reconnect to the vector source the next time it is needed by a request. This is useful as the store can keep state, such as a connection pool, and the structure of the feature types it's serving.

Parameters:

Name Type Description Default
name str

The name of the data store.

required
workspace str

The name of the workspace containing the data stores.

required

Returns:

Type Description
str

Success message.

Example

To reset the caches of a data store, use the following code:

geoserver.reset_data_store_caches("my_data_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
def reset_data_store_caches(self, name: str, *, workspace: str) -> str:
    """Resets caches for this data store.
    This operation is used to force GeoServer to drop caches associated to this data store,
    and reconnect to the vector source the next time it is needed by a request.
    This is useful as the store can keep state, such as a connection pool,
    and the structure of the feature types it's serving.

    Args:
        name: The name of the data store.
        workspace: The name of the workspace containing the data stores.

    Returns:
        Success message.

    Example:
        To reset the caches of a data store, use the following code:

        ```python
        geoserver.reset_data_store_caches("my_data_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{name}/reset"
    self._request(method="put", url=url)  # NOTE: Can also be a POST
    return OK_MESSAGE

get_coverages

get_coverages(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_coverages(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_coverages(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

List the coverages available for the provided workspace and data store.

Parameters:

Name Type Description Default
workspace str

The name of the workspace containing the data stores.

required
store Optional[str]

Optional. The name of the data store.

None
list Optional[str]

Optional. The list parameter is used to filter over resulting resource names attribute using Java regular expressions.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all coverages in the workspace and data store.

Example

To get the list of all coverages in a workspace, use the following code:

geoserver.get_coverages(workspace="my_workspace")

To specify a coverage store, use the following code:

geoserver.get_coverages(workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
def get_coverages(
    self,
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """List the coverages available for the provided workspace and data store.

    Args:
        workspace: The name of the workspace containing the data stores.
        store: Optional. The name of the data store.
        list: Optional. The list parameter is used to filter over resulting resource names attribute using Java regular expressions.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The list of all coverages in the workspace and data store.

    Example:
        To get the list of all coverages in a workspace, use the following code:

        ```python
        geoserver.get_coverages(workspace="my_workspace")
        ```

        To specify a coverage store, use the following code:

        ```python
        geoserver.get_coverages(workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coverages.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages.{format}"

    response = self._request(method="get", url=url, params=dict(list=list))
    return response.json() if format == "json" else response.text

coverage_exists

coverage_exists(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
) -> bool

Check if a coverage exists.

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the coverage store.

None

Returns:

Type Description
bool

True if the coverage exists, False otherwise.

Example
geoserver.coverage_exists("my_coverage", workspace="my_workspace")
Source code in geoserver/geoserver.py
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
def coverage_exists(self, name: str, *, workspace: str, store: Optional[str] = None) -> bool:
    """Check if a coverage exists.

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace.
        store: Optional. The name of the coverage store.

    Returns:
        True if the coverage exists, False otherwise.

    Example:
        ```python
        geoserver.coverage_exists("my_coverage", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coverages/{name}.xml"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_coverage

create_coverage(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
) -> str

Creates a new coverage, the underlying data store must exist.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body the coverage to be created.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the coverage store.

None

Returns:

Type Description
str

The created coverage.

Example

To create a new coverage, use the following code:

# Check the GeoServer official documentation for the body structure
body = "..."

geoserver.create_coverage(body, workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
def create_coverage(self, body: Union[str, Dict[str, Any]], *, workspace: str, store: Optional[str] = None) -> str:
    """Creates a new coverage, the underlying data store must exist.

    Args:
        body: The body the coverage to be created.
        workspace: The name of the workspace.
        store: Optional. The name of the coverage store.

    Returns:
        The created coverage.

    Example:
        To create a new coverage, use the following code:

        ```python
        # Check the GeoServer official documentation for the body structure
        body = "..."

        geoserver.create_coverage(body, workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coverages"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_coverage

get_coverage(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_coverage(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_coverage(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get an individual coverage.

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the coverage datastore. Defaults to None.

None
quiet_on_not_found bool

Optional. If true, the server will not report an error if the coverage is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested coverage.

Example

To get a coverage, use the following code:

geoserver.get_coverage("my_coverage", workspace="my_workspace")

To specify a coverage store, use the following code:

geoserver.get_coverage("my_coverage", workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
def get_coverage(
    self,
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Get an individual coverage.

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace.
        store: Optional. The name of the coverage datastore. Defaults to None.
        quiet_on_not_found: Optional. If true, the server will not report an error if the coverage is not found.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The requested coverage.

    Example:
        To get a coverage, use the following code:

        ```python
        geoserver.get_coverage("my_coverage", workspace="my_workspace")
        ```

        To specify a coverage store, use the following code:

        ```python
        geoserver.get_coverage("my_coverage", workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coverages/{name}.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}.{format}"

    response = self._request(method="get", url=url, params=dict(quietOnNotFound=quiet_on_not_found))
    return response.json() if format == "json" else response.text

get_coverage_index

get_coverage_index(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_coverage_index(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_coverage_index(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get an individual coverage index structure.

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the coverage datastore. Defaults to None.

None
quiet_on_not_found bool

Optional. If true, the server will not report an error if the coverage is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested coverage.

Example

To get a coverage index, use the following code:

geoserver.get_coverage_index("my_coverage", workspace="my_workspace")

To specify a coverage store, use the following code:

geoserver.get_coverage_index("my_coverage", workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
def get_coverage_index(
    self,
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Get an individual coverage index structure.

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace.
        store: Optional. The name of the coverage datastore. Defaults to None.
        quiet_on_not_found: Optional. If true, the server will not report an error if the coverage is not found.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The requested coverage.

    Example:
        To get a coverage index, use the following code:

        ```python
        geoserver.get_coverage_index("my_coverage", workspace="my_workspace")
        ```

        To specify a coverage store, use the following code:

        ```python
        geoserver.get_coverage_index("my_coverage", workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coverages/{name}/index.{format}"
    if store is not None:
        url = (
            f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}/index.{format}"
        )

    response = self._request(method="get", url=url, params=dict(quietOnNotFound=quiet_on_not_found))
    return response.json() if format == "json" else response.text

update_coverage

update_coverage(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: str,
) -> str

Update an individual coverage

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
body Union[str, Dict[str, Any]]

The body of the request used to update the coverage.

required
workspace str

The name of the workspace.

required
store str

The name of the coverage datastore

required

Returns:

Type Description
str

Success message.

Example

To update a coverage, use the following code:

# Check the GeoServer official documentation for the body structure
body = "..."

geoserver.update_coverage("my_coverage", body, workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
def update_coverage(self, name: str, body: Union[str, Dict[str, Any]], *, workspace: str, store: str) -> str:
    """Update an individual coverage

    Args:
        name: The name of the coverage.
        body: The body of the request used to update the coverage.
        workspace: The name of the workspace.
        store: The name of the coverage datastore

    Returns:
        Success message.

    Example:
        To update a coverage, use the following code:

        ```python
        # Check the GeoServer official documentation for the body structure
        body = "..."

        geoserver.update_coverage("my_coverage", body, workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_coverage

delete_coverage(
    name: str,
    *,
    workspace: str,
    store: str,
    recurse: bool = False,
) -> str

Delete a coverage (optionally recursively deleting layers).

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace.

required
store str

The name of the coverage datastore

required
recurse bool

Optional. If true all stores containing the resource are also removed.

False

Returns:

Type Description
str

Success message.

Example

To delete a coverage, use the following code:

geoserver.delete_coverage("my_coverage", workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
def delete_coverage(self, name: str, *, workspace: str, store: str, recurse: bool = False) -> str:
    """Delete a coverage (optionally recursively deleting layers).

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace.
        store: The name of the coverage datastore
        recurse: Optional. If true all stores containing the resource are also removed.

    Returns:
        Success message.

    Example:
        To delete a coverage, use the following code:

        ```python
        geoserver.delete_coverage("my_coverage", workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}"
    params = dict(recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

reset_coverage_caches

reset_coverage_caches(
    name: str, *, workspace: str, store: str
) -> str

Resets raster caches for this coverage. This operation is used to force GeoServer to drop caches associated to this coverage, and reconnect to the raster source the next time it is needed by a request. This is useful as the readers often cache some information about the bounds, coordinate system and image structure that might have changed in the meantime. Warning, the band structure is stored as part of the coverage configuration and won't be modified by this call, in case of need it should be modified issuing a PUT request against the coverage resource itself.

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace.

required
store str

The name of the coverage datastore

required

Returns:

Type Description
str

Success message.

Example

To reset the caches of a coverage, use the following code:

geoserver.reset_coverage_caches("my_coverage", workspace="my_workspace", store="my_coverage_store")
Source code in geoserver/geoserver.py
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
def reset_coverage_caches(self, name: str, *, workspace: str, store: str) -> str:
    """Resets raster caches for this coverage.
    This operation is used to force GeoServer to drop caches associated to this coverage,
    and reconnect to the raster source the next time it is needed by a request.
    This is useful as the readers often cache some information about the bounds,
    coordinate system and image structure that might have changed in the meantime.
    Warning, the band structure is stored as part of the coverage configuration and won't be modified by this call,
    in case of need it should be modified issuing a PUT request against the coverage resource itself.

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace.
        store: The name of the coverage datastore

    Returns:
        Success message.

    Example:
        To reset the caches of a coverage, use the following code:

        ```python
        geoserver.reset_coverage_caches("my_coverage", workspace="my_workspace", store="my_coverage_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}/reset"
    self._request(method="put", url=url)  # NOTE: Can also be a POST
    return OK_MESSAGE

get_coverage_stores

get_coverage_stores(
    *, workspace: str, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_coverage_stores(
    *, workspace: str, format: Literal["xml"]
) -> str
get_coverage_stores(
    *,
    workspace: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays a list of all styles on the server.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all coverage stores in the workspace.

Example

To get the list of all coverage stores in a workspace, use the following code:

geoserver.get_coverage_stores(workspace="my_workspace")
Source code in geoserver/geoserver.py
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
def get_coverage_stores(
    self, *, workspace: str, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays a list of all styles on the server.

    Args:
        workspace: The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The list of all coverage stores in the workspace.

    Example:
        To get the list of all coverage stores in a workspace, use the following code:

        ```python
        geoserver.get_coverage_stores(workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

coverage_store_exists

coverage_store_exists(name: str, *, workspace: str) -> bool

Check if a coverage store exists in a workspace.

Parameters:

Name Type Description Default
name str

The name of the coverage store.

required
workspace str

The name of the workspace containing the coverage stores.

required

Returns:

Type Description
bool

True if the coverage store exists, False otherwise.

Example

To check if a coverage store exists in a workspace, use the following code:

geoserver.coverage_store_exists("my_coverage_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
def coverage_store_exists(self, name: str, *, workspace: str) -> bool:
    """Check if a coverage store exists in a workspace.

    Args:
        name: The name of the coverage store.
        workspace: The name of the workspace containing the coverage stores.

    Returns:
        True if the coverage store exists, False otherwise.

    Example:
        To check if a coverage store exists in a workspace, use the following code:

        ```python
        geoserver.coverage_store_exists("my_coverage_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{name}.xml"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

coveragestore_exists

coveragestore_exists(name: str, *, workspace: str) -> bool

Check if a coverage store exists in a workspace.

Warning

Deprecated, use coverage_store_exists instead.

Source code in geoserver/geoserver.py
902
903
904
905
906
907
908
909
@deprecated("Use `coverage_store_exists` instead.")
def coveragestore_exists(self, name: str, *, workspace: str) -> bool:
    """Check if a coverage store exists in a workspace.

    Warning:
        Deprecated, use [`coverage_store_exists`][geoserver.geoserver.GeoServer.coverage_store_exists] instead.
    """
    return self.coverage_store_exists(name, workspace=workspace)

create_coverage_store

create_coverage_store(
    body: Union[str, Dict[str, Any]], *, workspace: str
) -> str

Adds a new coverage store.

Warning

It is preferred to use the upload_coverage_store method to upload a new coverage store.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the coverage store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Example

To create a new coverage store, use the following code:

# Check the GeoServer official documentation for the body structure
body = "..."

geoserver.create_coverage_store(body, workspace="my_workspace")
Source code in geoserver/geoserver.py
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
def create_coverage_store(self, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Adds a new coverage store.

    Warning:
        It is preferred to use the `upload_coverage_store` method to upload a new coverage store.

    Args:
        body: The body of the request used to create the coverage store.
        workspace: The name of the workspace.

    Returns:
        Success message.

    Example:
        To create a new coverage store, use the following code:

        ```python
        # Check the GeoServer official documentation for the body structure
        body = "..."

        geoserver.create_coverage_store(body, workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

upload_coverage_store

upload_coverage_store(
    file: Union[str, Path, BufferedReader],
    *,
    workspace: str,
    name: Optional[str] = None,
    method: Literal[
        "auto", "file", "external", "url", "remote"
    ] = "auto",
    format: Union[
        Literal[
            "geotiff", "worldimage", "imagemosaic", "netcdf"
        ],
        str,
    ],
    update_bbox: bool = False,
    configure: Literal["none", "first", "all"] = "all",
    use_jai_imageread: bool = False,
    coverage_name: Optional[str] = None,
    filename: Optional[str] = None,
) -> str

Creates a new coverage store, or overwrites an existing one, from a file.

Tip

This method is the preferred way to upload a new coverage store.

Warning

Uploading to an existing image mosaic replaces its configuration but does not add the new files to its index. Use harvest_coverage_store to add granules to an existing mosaic.

Note

The name parameter is inferred from the file name when file is a path or a file object opened from a path. It is required otherwise.

Note

The file name of the resource can be overwritten by: - Providing the filename parameter. - Using the name parameter. In this case, if the filename is not provided, the file name will be the same as the store name.

Parameters:

Name Type Description Default
file Union[str, Path, BufferedReader]

The data to upload: a local path or file object (method="file"), the absolute path of a file on the GeoServer machine (method="external"), or a URL (method="url" or method="remote").

required
workspace str

The name of the workspace.

required
name Optional[str]

Optional. The name of the coverage store.

None
method Literal['auto', 'file', 'external', 'url', 'remote']

Optional. How GeoServer gets the data. Defaults to "auto".

  • "file": uploads the local file or file object in the request body.
  • "external": uses a file that already exists on the GeoServer machine. file is its absolute path on the server, e.g. "/data/raster.tif". GeoServer 2.28 and 3.x reject file: URLs here, while older releases expect one (e.g. "file:///data/raster.tif").
  • "url": GeoServer downloads the file from file, a URL it can reach.
  • "remote": GeoServer reads the dataset from file, a URL (e.g. on cloud storage), without copying it.
  • "auto": "url" for http:// and https:// URLs, "external" for file: URLs and "file" otherwise.
'auto'
format Union[Literal['geotiff', 'worldimage', 'imagemosaic', 'netcdf'], str]

The coverage format, as GeoServer names it: "geotiff", "imagemosaic", or a format added by an extension (e.g. "netcdf" with the NetCDF extension). The name is case-sensitive. When the format is unknown, the error raised by GeoServer lists the formats it accepts.

required
update_bbox bool

Optional. Whether to recalculate the native bounding box of the layer. GeoServer reads it when harvesting granules into an existing store. Defaults to False.

False
configure Literal['none', 'first', 'all']

Optional. Which coverages to configure as layers after creating the store: "all" (default), "first" or "none".

'all'
use_jai_imageread bool

Optional. Whether to use deferred loading while configuring the coverage. Defaults to False.

False
coverage_name Optional[str]

Optional. The name of the coverage (and layer) created from the file.

None
filename Optional[str]

Optional. The target file name on the server, which avoids clashes with existing files. Defaults to the store name with the extension of file. Only used with method="file".

None

Returns:

Type Description
str

Success message.

Example

To upload a new coverage store from a local file, use the following code:

geoserver.upload_coverage_store("my_raster.tif", workspace="my_workspace", name="my_coverage_store", format="geotiff")

Or, using a file object:

with open("my_raster.tif", "rb") as f:
    geoserver.upload_coverage_store(f, workspace="my_workspace", name="my_coverage_store", format="geotiff")

To create a store from a file that is already on the GeoServer machine:

geoserver.upload_coverage_store("/data/my_raster.tif", method="external", workspace="my_workspace", format="geotiff")
Source code in geoserver/geoserver.py
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
def upload_coverage_store(
    self,
    file: Union[str, Path, BufferedReader],
    *,
    workspace: str,
    name: Optional[str] = None,
    method: Literal["auto", "file", "external", "url", "remote"] = "auto",
    format: Union[Literal["geotiff", "worldimage", "imagemosaic", "netcdf"], str],
    update_bbox: bool = False,
    configure: Literal["none", "first", "all"] = "all",
    use_jai_imageread: bool = False,
    coverage_name: Optional[str] = None,
    filename: Optional[str] = None,
) -> str:
    """Creates a new coverage store, or overwrites an existing one, from a file.

    Tip:
        This method is the preferred way to upload a new coverage store.

    Warning:
        Uploading to an existing image mosaic replaces its configuration but does not add the new files
        to its index. Use [`harvest_coverage_store`][geoserver.geoserver.GeoServer.harvest_coverage_store]
        to add granules to an existing mosaic.

    Note:
        The `name` parameter is inferred from the file name when `file` is a path or a file object opened
        from a path. It is required otherwise.

    Note:
        The file name of the resource can be overwritten by:
        - Providing the `filename` parameter.
        - Using the `name` parameter. In this case, if the `filename` is not provided,
            the file name will be the same as the store name.

    Args:
        file: The data to upload: a local path or file object (`method="file"`), the absolute path of a file
            on the GeoServer machine (`method="external"`), or a URL (`method="url"` or `method="remote"`).
        workspace: The name of the workspace.
        name: Optional. The name of the coverage store.
        method: Optional. How GeoServer gets the data. Defaults to "auto".

            - "file": uploads the local file or file object in the request body.
            - "external": uses a file that already exists on the GeoServer machine. `file` is its absolute
                path on the server, e.g. "/data/raster.tif". GeoServer 2.28 and 3.x reject `file:` URLs
                here, while older releases expect one (e.g. "file:///data/raster.tif").
            - "url": GeoServer downloads the file from `file`, a URL it can reach.
            - "remote": GeoServer reads the dataset from `file`, a URL (e.g. on cloud storage), without
                copying it.
            - "auto": "url" for `http://` and `https://` URLs, "external" for `file:` URLs and "file" otherwise.
        format: The coverage format, as GeoServer names it: "geotiff", "imagemosaic", or a format added by an
            extension (e.g. "netcdf" with the NetCDF extension). The name is case-sensitive. When the format
            is unknown, the error raised by GeoServer lists the formats it accepts.
        update_bbox: Optional. Whether to recalculate the native bounding box of the layer. GeoServer reads it
            when harvesting granules into an existing store. Defaults to `False`.
        configure: Optional. Which coverages to configure as layers after creating the store:
            "all" (default), "first" or "none".
        use_jai_imageread: Optional. Whether to use deferred loading while configuring the coverage.
            Defaults to `False`.
        coverage_name: Optional. The name of the coverage (and layer) created from the file.
        filename: Optional. The target file name on the server, which avoids clashes with existing files.
            Defaults to the store name with the extension of `file`. Only used with `method="file"`.

    Returns:
        Success message.

    Example:
        To upload a new coverage store from a local file, use the following code:

        ```python
        geoserver.upload_coverage_store("my_raster.tif", workspace="my_workspace", name="my_coverage_store", format="geotiff")
        ```

        Or, using a file object:

        ```python
        with open("my_raster.tif", "rb") as f:
            geoserver.upload_coverage_store(f, workspace="my_workspace", name="my_coverage_store", format="geotiff")
        ```

        To create a store from a file that is already on the GeoServer machine:

        ```python
        geoserver.upload_coverage_store("/data/my_raster.tif", method="external", workspace="my_workspace", format="geotiff")
        ```
    """
    if isinstance(file, Path):
        file = file.as_posix()
    local_name = file_name(file)
    if local_name is not None:
        name = name or Path(local_name).stem
        filename = filename or f"{name}{Path(local_name).suffix}"

    if name is None:
        raise ValueError("The `name` parameter is required")

    params: Dict[str, Any] = dict(
        filename=filename,
        configure=configure,
        USE_JAI_IMAGEREAD=use_jai_imageread,
        coverageName=coverage_name,
    )
    if update_bbox:
        params["updateBBox"] = True

    method = self._resolve_upload_method(file, method)
    self._send_coverage_store_file(
        "put", file, workspace=workspace, name=name, method=method, format=format, params=params
    )
    return CREATED_MESSAGE

harvest_coverage_store

harvest_coverage_store(
    file: Union[str, Path, BufferedReader],
    *,
    workspace: str,
    name: str,
    method: Literal[
        "auto", "file", "external", "url", "remote"
    ] = "auto",
    format: Union[
        Literal["imagemosaic"], str
    ] = "imagemosaic",
    filename: Optional[str] = None,
    update_bbox: bool = False,
) -> str

Harvests new granules into an existing structured coverage store, such as an image mosaic.

Unlike upload_coverage_store, which creates or replaces a store, this method adds the files to the index of an existing one. GeoServer answers with an error (405) if the store cannot harvest granules, e.g. a single GeoTIFF store.

Note

A ZIP archive harvests every granule it contains. A single local file is sent inside a ZIP archive, because GeoServer rejects a lone granule uploaded to a mosaic.

Parameters:

Name Type Description Default
file Union[str, Path, BufferedReader]

The granules to harvest: a local file, ZIP archive or file object (method="file"), the absolute path of a file or directory on the GeoServer machine (method="external"), or a URL (method="url" or method="remote").

required
workspace str

The name of the workspace.

required
name str

The name of the existing coverage store.

required
method Literal['auto', 'file', 'external', 'url', 'remote']

Optional. How GeoServer gets the data, see upload_coverage_store. Defaults to "auto".

'auto'
format Union[Literal['imagemosaic'], str]

Optional. The format of the store. Defaults to "imagemosaic".

'imagemosaic'
filename Optional[str]

Optional. The granule name in the mosaic, which avoids clashes and carries the dimension values (time, elevation, ...) that the mosaic extracts from file names. Defaults to the name of the file. Required for a file object without a name. Only used with method="file".

None
update_bbox bool

Optional. Whether to recalculate the native bounding box of the layer after harvesting. Defaults to False.

False

Returns:

Type Description
str

Success message.

Example

To add a local granule to an existing mosaic:

geoserver.harvest_coverage_store("granule_2024_02.tif", workspace="my_workspace", name="my_mosaic")

To harvest a file, or a whole directory, that is already on the GeoServer machine:

geoserver.harvest_coverage_store("/data/mosaic/granule_2024_02.tif", method="external", workspace="my_workspace", name="my_mosaic")
Source code in geoserver/geoserver.py
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
def harvest_coverage_store(
    self,
    file: Union[str, Path, BufferedReader],
    *,
    workspace: str,
    name: str,
    method: Literal["auto", "file", "external", "url", "remote"] = "auto",
    format: Union[Literal["imagemosaic"], str] = "imagemosaic",
    filename: Optional[str] = None,
    update_bbox: bool = False,
) -> str:
    """Harvests new granules into an existing structured coverage store, such as an image mosaic.

    Unlike [`upload_coverage_store`][geoserver.geoserver.GeoServer.upload_coverage_store], which creates or
    replaces a store, this method adds the files to the index of an existing one. GeoServer answers with an
    error (405) if the store cannot harvest granules, e.g. a single GeoTIFF store.

    Note:
        A ZIP archive harvests every granule it contains. A single local file is sent inside a ZIP archive,
        because GeoServer rejects a lone granule uploaded to a mosaic.

    Args:
        file: The granules to harvest: a local file, ZIP archive or file object (`method="file"`), the absolute
            path of a file or directory on the GeoServer machine (`method="external"`), or a URL
            (`method="url"` or `method="remote"`).
        workspace: The name of the workspace.
        name: The name of the existing coverage store.
        method: Optional. How GeoServer gets the data, see
            [`upload_coverage_store`][geoserver.geoserver.GeoServer.upload_coverage_store]. Defaults to "auto".
        format: Optional. The format of the store. Defaults to "imagemosaic".
        filename: Optional. The granule name in the mosaic, which avoids clashes and carries the dimension
            values (time, elevation, ...) that the mosaic extracts from file names. Defaults to the name of
            the file. Required for a file object without a name. Only used with `method="file"`.
        update_bbox: Optional. Whether to recalculate the native bounding box of the layer after harvesting.
            Defaults to `False`.

    Returns:
        Success message.

    Example:
        To add a local granule to an existing mosaic:

        ```python
        geoserver.harvest_coverage_store("granule_2024_02.tif", workspace="my_workspace", name="my_mosaic")
        ```

        To harvest a file, or a whole directory, that is already on the GeoServer machine:

        ```python
        geoserver.harvest_coverage_store("/data/mosaic/granule_2024_02.tif", method="external", workspace="my_workspace", name="my_mosaic")
        ```
    """
    if isinstance(file, Path):
        file = file.as_posix()

    params: Dict[str, Any] = {}
    if update_bbox:
        params["updateBBox"] = True

    method = self._resolve_upload_method(file, method)
    if method != "file" or is_zip(file):
        self._send_coverage_store_file(
            "post", file, workspace=workspace, name=name, method=method, format=format, params=params
        )
        return UPDATED_MESSAGE

    granule_name = filename or file_name(file)
    if granule_name is None:
        raise ValueError("The `filename` parameter is required to harvest a file object without a name.")

    with tempfile.TemporaryFile() as archive:
        with zipfile.ZipFile(archive, "w") as zf:
            if isinstance(file, str):
                zf.write(file, arcname=granule_name)
            else:
                with zf.open(granule_name, "w") as entry:
                    shutil.copyfileobj(file, entry)
        archive.seek(0)
        self._send_coverage_store_file(
            "post", archive, workspace=workspace, name=name, method="file", format=format, params=params
        )
    return UPDATED_MESSAGE

get_coverage_store

get_coverage_store(
    name: str,
    *,
    workspace: str,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_coverage_store(
    name: str,
    *,
    workspace: str,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_coverage_store(
    name: str,
    *,
    workspace: str,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get an individual coverage store.

Parameters:

Name Type Description Default
name str

The name of the coverage store.

required
workspace str

The name of the workspace.

required
quiet_on_not_found bool

Optional. If true, the server will not report an error if the coverage store is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested coverage store.

Example

To get a coverage store, use the following code:

geoserver.get_coverage_store("my_coverage_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
def get_coverage_store(
    self, name: str, *, workspace: str, quiet_on_not_found: bool = False, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Get an individual coverage store.

    Args:
        name: The name of the coverage store.
        workspace: The name of the workspace.
        quiet_on_not_found: Optional. If true, the server will not report an error if the coverage store is not found.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The requested coverage store.

    Example:
        To get a coverage store, use the following code:

        ```python
        geoserver.get_coverage_store("my_coverage_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{name}.{format}"
    response = self._request(method="get", url=url, params=dict(quietOnNotFound=quiet_on_not_found))
    return response.json()

update_coverage_store

update_coverage_store(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
) -> str

Modifies a single coverage store.

Parameters:

Name Type Description Default
name str

The name of the coverage store.

required
body Union[str, Dict[str, Any]]

The body of the request used to update the coverage store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Example

To update a coverage store, use the following code:

# Check the GeoServer official documentation for the body structure
body = "..."

geoserver.update_coverage_store("my_coverage_store", body, workspace="my_workspace")
Source code in geoserver/geoserver.py
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
def update_coverage_store(self, name: str, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Modifies a single coverage store.

    Args:
        name: The name of the coverage store.
        body: The body of the request used to update the coverage store.
        workspace: The name of the workspace.

    Returns:
        Success message.

    Example:
        To update a coverage store, use the following code:

        ```python
        # Check the GeoServer official documentation for the body structure
        body = "..."

        geoserver.update_coverage_store("my_coverage_store", body, workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_coverage_store

delete_coverage_store(
    name: str,
    *,
    workspace: str,
    purge: Literal["none", "metadata", "all"] = "all",
    recurse: bool = False,
) -> str

Deletes a coverage store.

Parameters:

Name Type Description Default
name str

The name of the coverage store.

required
workspace str

The name of the workspace.

required
purge Literal['none', 'metadata', 'all']

Optional. The purge parameter specifies if and how the underlying raster data source is deleted. When set to "none" data and auxiliary files are preserved. When set to "metadata" delete only auxiliary files and metadata. It's recommended when data files (such as granules) should not be deleted from disk. Finally, when set to "all both data and auxiliary files are removed. Defaults to "none".

'all'
recurse bool

Optional. The recurse controls recursive deletion. When set to true all resources contained in the store are also removed. The default to false.

False

Returns:

Type Description
str

Success message.

Example

To delete a coverage store, use the following code:

geoserver.delete_coverage_store("my_coverage_store", workspace="my_workspace")

To remove all resources contained in the store, use the following code:

geoserver.delete_coverage_store("my_coverage_store", workspace="my_workspace", recurse=True)
Source code in geoserver/geoserver.py
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
def delete_coverage_store(
    self, name: str, *, workspace: str, purge: Literal["none", "metadata", "all"] = "all", recurse: bool = False
) -> str:
    """Deletes a coverage store.

    Args:
        name: The name of the coverage store.
        workspace: The name of the workspace.
        purge: Optional. The purge parameter specifies if and how the underlying raster data source is deleted.
            When set to "none" data and auxiliary files are preserved.
            When set to "metadata" delete only auxiliary files and metadata.
            It's recommended when data files (such as granules) should not be deleted from disk.
            Finally, when set to "all both data and auxiliary files are removed.
            Defaults to "none".
        recurse: Optional. The recurse controls recursive deletion.
            When set to true all resources contained in the store are also removed.
            The default to false.

    Returns:
        Success message.

    Example:
        To delete a coverage store, use the following code:

        ```python
        geoserver.delete_coverage_store("my_coverage_store", workspace="my_workspace")
        ```

        To remove all resources contained in the store, use the following code:

        ```python
        geoserver.delete_coverage_store("my_coverage_store", workspace="my_workspace", recurse=True)
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{name}"
    params = dict(purge=purge, recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

reset_coverage_store_caches

reset_coverage_store_caches(
    name: str, *, workspace: str
) -> str

Resets raster caches for this coverage store. This operation is used to force GeoServer to drop caches associated to this coverage store, and reconnect to the raster source the next time it is needed by a request. This is useful as the readers often cache some information about the bounds, coordinate system and image structure that might have changed in the meantime.

Parameters:

Name Type Description Default
name str

The name of the coverage store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Example

To reset the caches of a coverage store, use the following code:

geoserver.reset_coverage_store_caches("my_coverage_store", workspace="my_workspace")
Source code in geoserver/geoserver.py
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
def reset_coverage_store_caches(self, name: str, *, workspace: str) -> str:
    """Resets raster caches for this coverage store.
    This operation is used to force GeoServer to drop caches associated to this coverage store,
    and reconnect to the raster source the next time it is needed by a request.
    This is useful as the readers often cache some information about the bounds,
    coordinate system and image structure that might have changed in the meantime.

    Args:
        name: The name of the coverage store.
        workspace: The name of the workspace.

    Returns:
        Success message.

    Example:
        To reset the caches of a coverage store, use the following code:

        ```python
        geoserver.reset_coverage_store_caches("my_coverage_store", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{name}/reset"
    self._request(method="put", url=url)
    return OK_MESSAGE

get_feature_types

get_feature_types(
    *,
    workspace: str,
    store: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_feature_types(
    *,
    workspace: str,
    store: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_feature_types(
    *,
    workspace: str,
    store: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

List all feature types in the workspace.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
store Optional[str]

The name of the data store.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all feature types in the workspace.

Example

To get the list of all feature types in a workspace, use the following code:

geoserver.get_feature_types(workspace="my_workspace")
Source code in geoserver/geoserver.py
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
def get_feature_types(
    self, *, workspace: str, store: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """List all feature types in the workspace.

    Args:
        workspace: The name of the workspace.
        store: The name of the data store.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The list of all feature types in the workspace.

    Example:
        To get the list of all feature types in a workspace, use the following code:

        ```python
        geoserver.get_feature_types(workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

feature_type_exists

feature_type_exists(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
) -> bool

Check if a feature type exists.

Parameters:

Name Type Description Default
name str

The name of the feature type.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the data store.

None

Returns:

Type Description
bool

True if the feature type exists, False otherwise.

Example
geoserver.feature_type_exists("my_feature_type", workspace="my_workspace")
Source code in geoserver/geoserver.py
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
def feature_type_exists(self, name: str, *, workspace: str, store: Optional[str] = None) -> bool:
    """Check if a feature type exists.

    Args:
        name: The name of the feature type.
        workspace: The name of the workspace.
        store: Optional. The name of the data store.

    Returns:
        True if the feature type exists, False otherwise.

    Example:
        ```python
        geoserver.feature_type_exists("my_feature_type", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes/{name}.xml"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_feature_type

create_feature_type(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
) -> str

Create a new feature type.

Note

When creating a new feature type via POST, if no underlying dataset with the specified name exists an attempt will be made to create it. This will work only in cases where the underlying data format supports the creation of new types (such as a database). When creating a feature type in this manner the client should include all attribute information in the feature type representation.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the feature type.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the data store.

None

Returns:

Type Description
str

Success message.

Example

To create a new feature type, use the following code:

# Check the GeoServer official documentation for the body structure
body = "..."

geoserver.create_feature_type(body, workspace="my_workspace", store="my_data_store")
Source code in geoserver/geoserver.py
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
def create_feature_type(
    self, body: Union[str, Dict[str, Any]], *, workspace: str, store: Optional[str] = None
) -> str:
    """Create a new feature type.

    Note:
        When creating a new feature type via POST, if no underlying dataset
        with the specified name exists an attempt will be made to create it.
        This will work only in cases where the underlying data format supports the creation of new types (such as a database).
        When creating a feature type in this manner the client should include all attribute information
        in the feature type representation.

    Args:
        body: The body of the request used to create the feature type.
        workspace: The name of the workspace.
        store: Optional. The name of the data store.

    Returns:
        Success message.

    Example:
        To create a new feature type, use the following code:

        ```python
        # Check the GeoServer official documentation for the body structure
        body = "..."

        geoserver.create_feature_type(body, workspace="my_workspace", store="my_data_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_feature_type

get_feature_type(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_feature_type(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_feature_type(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get an individual feature type.

Parameters:

Name Type Description Default
name str

The name of the feature type.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the data store.

None
quiet_on_not_found bool

Optional. If true, the server will not report an error if the feature type is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested feature type.

Example

To get a feature type, use the following code:

geoserver.get_feature_type("my_feature_type", workspace="my_workspace")
Source code in geoserver/geoserver.py
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
def get_feature_type(
    self,
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Get an individual feature type.

    Args:
        name: The name of the feature type.
        workspace: The name of the workspace.
        store: Optional. The name of the data store.
        quiet_on_not_found: Optional. If true, the server will not report an error if the feature type is not found.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The requested feature type.

    Example:
        To get a feature type, use the following code:

        ```python
        geoserver.get_feature_type("my_feature_type", workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes/{name}.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes/{name}.{format}"

    response = self._request(method="get", url=url, params=dict(quietOnNotFound=quiet_on_not_found))
    return response.json() if format == "json" else response.text

update_feature_type

update_feature_type(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
    recalculate: Literal[
        "", "nativebbox", "nativebbox,latlonbbox"
    ] = "",
) -> str

Update an individual feature type.

Parameters:

Name Type Description Default
name str

The name of the feature type.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the feature type.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the data store.

None
recalculate Literal['', 'nativebbox', 'nativebbox,latlonbbox']

Optional. Specifies whether to recalculate properties for a feature type. Some properties of feature types are automatically recalculated when necessary. In particular, the native bounding box is recalculated when the projection or projection policy are changed, and the lat/lon bounding box is recalculated when the native bounding box is recalculated, or when a new native bounding box is explicitly provided in the request. (The native and lat/lon bounding boxes are not automatically recalculated when they are explicitly included in the request.) In addition, the client may explicitly request a fixed set of fields to calculate, by including a comma-separated list of their names in the recalculate parameter. The empty parameter 'recalculate=' is useful avoid slow recalculation when operating against large datasets as 'recalculate=' avoids calculating any fields, regardless of any changes to projection, projection policy, etc. The nativebbox parameter 'recalculate=nativebbox' is used recalculates the native bounding box, while avoiding recalculating the lat/lon bounding box. Recalculate parameters can be used in together - 'recalculate=nativebbox,latlonbbox' can be used after a bulk import to recalculate both the native bounding box and the lat/lon bounding box. Finally, 'recalculate=attributes' can be used to reset the attributes and reload them from the original vector source. Pay attention to its usage, if attributes were explicitly configured to perform attribute selection, renaming, and other transformations, such configuration will be lost, resetting the feature type to the list of attributes found in the vector data source.

''

Returns:

Type Description
str

Success message.

Example

To update a feature type, use the following code:

# Check the GeoServer official documentation for the body structure
body = "..."

geoserver.update_feature_type("my_feature_type", body, workspace="my_workspace")
Source code in geoserver/geoserver.py
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
def update_feature_type(
    self,
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
    recalculate: Literal["", "nativebbox", "nativebbox,latlonbbox"] = "",
) -> str:
    """Update an individual feature type.

    Args:
        name: The name of the feature type.
        body: The body of the request used to modify the feature type.
        workspace: The name of the workspace.
        store: Optional. The name of the data store.
        recalculate: Optional. Specifies whether to recalculate properties for a feature type.
            Some properties of feature types are automatically recalculated when necessary.
            In particular, the native bounding box is recalculated when the projection or projection policy are changed,
            and the lat/lon bounding box is recalculated when the native bounding box is recalculated,
            or when a new native bounding box is explicitly provided in the request.
            (The native and lat/lon bounding boxes are not automatically recalculated when they are explicitly included in the request.)
            In addition, the client may explicitly request a fixed set of fields to calculate, by including a comma-separated list of their names in the recalculate parameter.
            The empty parameter 'recalculate=' is useful avoid slow recalculation when operating against large datasets as 'recalculate=' avoids calculating any fields,
            regardless of any changes to projection, projection policy, etc. The nativebbox parameter 'recalculate=nativebbox'
            is used recalculates the native bounding box, while avoiding recalculating the lat/lon bounding box. Recalculate parameters
            can be used in together - 'recalculate=nativebbox,latlonbbox' can be used after a bulk import to recalculate both
            the native bounding box and the lat/lon bounding box. Finally, 'recalculate=attributes' can be used to reset the attributes
            and reload them from the original vector source. Pay attention to its usage, if attributes were explicitly configured to
            perform attribute selection, renaming, and other transformations, such configuration will be lost, resetting the
            feature type to the list of attributes found in the vector data source.

    Returns:
        Success message.

    Example:
        To update a feature type, use the following code:

        ```python
        # Check the GeoServer official documentation for the body structure
        body = "..."

        geoserver.update_feature_type("my_feature_type", body, workspace="my_workspace")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes/{name}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes/{name}"

    params = dict(recalculate=recalculate)
    self._request(method="put", url=url, body=body, params=params)
    return UPDATED_MESSAGE

delete_feature_type

delete_feature_type(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    recurse: bool = False,
) -> str

Delete an individual feature type.

Parameters:

Name Type Description Default
name str

The name of the feature type.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the data store.

None
recurse bool

Optional. If true, all resources contained in the store are also removed.

False

Returns:

Type Description
str

Success message.

Example

To delete a feature type, use the following code:

geoserver.delete_feature_type("my_feature_type", workspace="my_workspace")

To also remove all associated resources, use the following code:

geoserver.delete_feature_type("my_feature_type", workspace="my_workspace", recurse=True)
Source code in geoserver/geoserver.py
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
def delete_feature_type(
    self, name: str, *, workspace: str, store: Optional[str] = None, recurse: bool = False
) -> str:
    """Delete an individual feature type.

    Args:
        name: The name of the feature type.
        workspace: The name of the workspace.
        store: Optional. The name of the data store.
        recurse: Optional. If true, all resources contained in the store are also removed.

    Returns:
        Success message.

    Example:
        To delete a feature type, use the following code:

        ```python
        geoserver.delete_feature_type("my_feature_type", workspace="my_workspace")
        ```

        To also remove all associated resources, use the following code:

        ```python
        geoserver.delete_feature_type("my_feature_type", workspace="my_workspace", recurse=True)
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes/{name}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes/{name}"

    params = dict(recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

reset_feature_type_caches

reset_feature_type_caches(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
) -> str

Resets caches for this feature type. This operation is used to force GeoServer to drop caches associated to this feature type, and reconnect to the vector source the next time it is needed by a request. This is useful as the store can keep state, such as a connection pool, and the structure of the feature types it's serving.

Parameters:

Name Type Description Default
name str

The name of the feature type.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the data store.

None

Returns:

Type Description
str

Success message.

Example

To reset the caches of a feature type, use the following code:

geoserver.reset_feature_type_caches("my_feature_type", workspace="my_workspace")

To specify a data store, use the following code:

geoserver.reset_feature_type_caches("my_feature_type", workspace="my_workspace", store="my_data_store")
Source code in geoserver/geoserver.py
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
def reset_feature_type_caches(self, name: str, *, workspace: str, store: Optional[str] = None) -> str:
    """Resets caches for this feature type.
    This operation is used to force GeoServer to drop caches associated to this feature type,
    and reconnect to the vector source the next time it is needed by a request.
    This is useful as the store can keep state, such as a connection pool,
    and the structure of the feature types it's serving.

    Args:
        name: The name of the feature type.
        workspace: The name of the workspace.
        store: Optional. The name of the data store.

    Returns:
        Success message.

    Example:
        To reset the caches of a feature type, use the following code:

        ```python
        geoserver.reset_feature_type_caches("my_feature_type", workspace="my_workspace")
        ```

        To specify a data store, use the following code:

        ```python
        geoserver.reset_feature_type_caches("my_feature_type", workspace="my_workspace", store="my_data_store")
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/featuretypes/{name}/reset"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/featuretypes/{name}/reset"

    self._request(method="put", url=url)
    return OK_MESSAGE

get_fonts

get_fonts(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_fonts(*, format: Literal['xml']) -> str
get_fonts(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

List all fonts available to GeoServer.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all fonts available to GeoServer.

Example

To get the list of all fonts available to GeoServer, use the following code:

geoserver.get_fonts()
Source code in geoserver/geoserver.py
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
def get_fonts(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """List all fonts available to GeoServer.

    Args:
        format: The format of the response. It can be either "json" or "xml".

    Returns:
        The list of all fonts available to GeoServer.

    Example:
        To get the list of all fonts available to GeoServer, use the following code:

        ```python
        geoserver.get_fonts()
        ```
    """
    url = f"{self.service_url}/rest/fonts.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

get_layer_groups

get_layer_groups(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_layer_groups(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_layer_groups(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

List all layer groups in the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all layer groups in the workspace.

Example

To get the list of all layer groups, use the following code:

geoserver.get_layer_groups()
Source code in geoserver/geoserver.py
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
def get_layer_groups(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """List all layer groups in the workspace.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The list of all layer groups in the workspace.

    Example:
        To get the list of all layer groups, use the following code:

        ```python
        geoserver.get_layer_groups()
        ```
    """
    url = f"{self.service_url}/rest/layergroups.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layergroups.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

layer_group_exists

layer_group_exists(
    name: str, *, workspace: Optional[str] = None
) -> bool

Check if a layer group exists.

Parameters:

Name Type Description Default
name str

The name of the layer group.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
bool

True if the layer group exists, False otherwise.

Source code in geoserver/geoserver.py
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
def layer_group_exists(self, name: str, *, workspace: Optional[str] = None) -> bool:
    """Check if a layer group exists.

    Args:
        name: The name of the layer group.
        workspace: Optional. The name of the workspace.

    Returns:
        True if the layer group exists, False otherwise.
    """
    url = f"{self.service_url}/rest/layergroups/{name}.xml"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layergroups/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_layer_group

create_layer_group(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Create a new layer group.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the layer group.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

The created layer group.

Source code in geoserver/geoserver.py
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
def create_layer_group(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Create a new layer group.

    Args:
        body: The body of the request used to create the layer group.
        workspace: Optional. The name of the workspace.

    Returns:
        The created layer group.
    """
    url = f"{self.service_url}/rest/layergroups"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layergroups"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_layer_group

get_layer_group(
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_layer_group(
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_layer_group(
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get an individual layer group.

Parameters:

Name Type Description Default
name str

The name of the layer group.

required
workspace Optional[str]

Optional. The name of the workspace.

None
quiet_on_not_found bool

Optional. If true, the server will not report an error if the layer group is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested layer group.

Source code in geoserver/geoserver.py
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
def get_layer_group(
    self,
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Get an individual layer group.

    Args:
        name: The name of the layer group.
        workspace: Optional. The name of the workspace.
        quiet_on_not_found: Optional. If true, the server will not report an error if the layer group is not found.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The requested layer group.
    """
    url = f"{self.service_url}/rest/layergroups/{name}.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layergroups/{name}.{format}"

    response = self._request(method="get", url=url, params=dict(quietOnNotFound=quiet_on_not_found))
    return response.json() if format == "json" else response.text

update_layer_group

update_layer_group(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Update an individual layer group.

Parameters:

Name Type Description Default
name str

The name of the layer group.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the layer group.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
def update_layer_group(
    self, name: str, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None
) -> str:
    """Update an individual layer group.

    Args:
        name: The name of the layer group.
        body: The body of the request used to modify the layer group.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/layergroups/{name}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layergroups/{name}"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_layer_group

delete_layer_group(
    name: str, *, workspace: Optional[str] = None
) -> str

Delete an individual layer group.

Parameters:

Name Type Description Default
name str

The name of the layer group.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
def delete_layer_group(self, name: str, *, workspace: Optional[str] = None) -> str:
    """Delete an individual layer group.

    Args:
        name: The name of the layer group.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/layergroups/{name}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layergroups/{name}"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_layers

get_layers(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_layers(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_layers(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

List all layers in the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all layers in the workspace.

Source code in geoserver/geoserver.py
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
def get_layers(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """List all layers in the workspace.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The list of all layers in the workspace.
    """
    url = f"{self.service_url}/rest/layers.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

layer_exists

layer_exists(
    name: str, *, workspace: Optional[str] = None
) -> bool

Check if a layer exists.

Parameters:

Name Type Description Default
name str

The name of the layer, qualified with its workspace (e.g. "my_workspace:my_layer") if workspace is not provided.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
bool

True if the layer exists, False otherwise.

Example
geoserver.layer_exists("my_layer", workspace="my_workspace")
geoserver.layer_exists("my_workspace:my_layer")
Source code in geoserver/geoserver.py
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
def layer_exists(self, name: str, *, workspace: Optional[str] = None) -> bool:
    """Check if a layer exists.

    Args:
        name: The name of the layer, qualified with its workspace (e.g. "my_workspace:my_layer") if `workspace`
            is not provided.
        workspace: Optional. The name of the workspace.

    Returns:
        True if the layer exists, False otherwise.

    Example:
        ```python
        geoserver.layer_exists("my_layer", workspace="my_workspace")
        geoserver.layer_exists("my_workspace:my_layer")
        ```
    """
    url = f"{self.service_url}/rest/layers/{name}.xml"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_layer

create_layer(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Creates a new layer.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the layer.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

The created layer.

Source code in geoserver/geoserver.py
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
def create_layer(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Creates a new layer.

    Args:
        body: The body of the request used to create the layer.
        workspace: Optional. The name of the workspace.

    Returns:
        The created layer.
    """
    url = f"{self.service_url}/rest/layers"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_layer

get_layer(
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_layer(
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_layer(
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get an individual layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace Optional[str]

Optional. The name of the workspace.

None
quiet_on_not_found bool

Optional. If true, the server will not report an error if the layer is not found.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested layer.

Source code in geoserver/geoserver.py
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
def get_layer(
    self,
    name: str,
    *,
    workspace: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Get an individual layer.

    Args:
        name: The name of the layer.
        workspace: Optional. The name of the workspace.
        quiet_on_not_found: Optional. If true, the server will not report an error if the layer is not found.
        format: Optional. The format of the response. It can be either "json" or "xml".

    Returns:
        The requested layer.
    """
    url = f"{self.service_url}/rest/layers/{name}.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}.{format}"

    response = self._request(method="get", url=url, params=dict(quietOnNotFound=quiet_on_not_found))
    return response.json() if format == "json" else response.text

update_layer

update_layer(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Update an individual layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the layer.

required
workspace Optional[str]

The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
def update_layer(self, name: str, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Update an individual layer.

    Args:
        name: The name of the layer.
        body: The body of the request used to modify the layer.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/layers/{name}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_layer

delete_layer(
    name: str, *, workspace: Optional[str] = None
) -> str

Delete an individual layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace Optional[str]

The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
def delete_layer(self, name: str, *, workspace: Optional[str] = None) -> str:
    """Delete an individual layer.

    Args:
        name: The name of the layer.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/layers/{name}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_logging

get_logging(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_logging(*, format: Literal['xml']) -> str
get_logging(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays a list of all logging settings on the server.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The logging settings.

Source code in geoserver/geoserver.py
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
def get_logging(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays a list of all logging settings on the server.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The logging settings.
    """
    url = f"{self.service_url}/rest/logging.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_logging

update_logging(body: Union[str, Dict[str, Any]]) -> str

Modify the logging settings on the server.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the logging settings.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
def update_logging(self, body: Union[str, Dict[str, Any]]) -> str:
    """Modify the logging settings on the server.

    Args:
        body: The body of the request used to modify the logging settings.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/logging"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

get_monitored_requests

get_monitored_requests(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_monitored_requests(*, format: Literal['xml']) -> str
get_monitored_requests(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Returns a list of all requests known to the monitoring system. If no list of fields is specified, the full list will be returned, with the exception of Class, Body and Error fields. The HTML format return a summary of the requests, and links to the single request to gather details.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The monitoring requests.

Source code in geoserver/geoserver.py
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
def get_monitored_requests(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Returns a list of all requests known to the monitoring system.
    If no list of fields is specified, the full list will be returned,
    with the exception of Class, Body and Error fields.
    The HTML format return a summary of the requests,
    and links to the single request to gather details.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The monitoring requests.
    """
    url = f"{self.service_url}/rest/monitor/requests.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

delete_monitored_requests

delete_monitored_requests() -> str

Removes a request from the monitoring system.

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
1955
1956
1957
1958
1959
1960
1961
1962
1963
def delete_monitored_requests(self) -> str:
    """Removes a request from the monitoring system.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/monitor/requests"
    self._request(method="delete", url=url)
    return OK_MESSAGE

get_monitored_request

get_monitored_request(
    id: str, *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_monitored_request(
    id: str, *, format: Literal["xml"]
) -> str
get_monitored_request(
    id: str, *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Returns the details of a single request.

Parameters:

Name Type Description Default
id str

The id of the request to retrieve.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The monitoring request.

Source code in geoserver/geoserver.py
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
def get_monitored_request(self, id: str, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Returns the details of a single request.

    Args:
        id: The id of the request to retrieve.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The monitoring request.
    """
    url = f"{self.service_url}/rest/monitor/requests/{id}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

get_namespaces

get_namespaces(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_namespaces(*, format: Literal['xml']) -> str
get_namespaces(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

List all namespaces on the server.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The list of all namespaces on the server.

Source code in geoserver/geoserver.py
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
def get_namespaces(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """List all namespaces on the server.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The list of all namespaces on the server.
    """
    url = f"{self.service_url}/rest/namespaces.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

namespace_exists

namespace_exists(name: str) -> bool

Check if a namespace exists.

Parameters:

Name Type Description Default
name str

The prefix of the namespace.

required

Returns:

Type Description
bool

True if the namespace exists, False otherwise.

Source code in geoserver/geoserver.py
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
def namespace_exists(self, name: str) -> bool:
    """Check if a namespace exists.

    Args:
        name: The prefix of the namespace.

    Returns:
        True if the namespace exists, False otherwise.
    """
    url = f"{self.service_url}/rest/namespaces/{name}.xml"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_namespace

create_namespace(body: Union[str, Dict[str, Any]]) -> str

Create a new namespace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the namespace.

required

Returns:

Type Description
str

The created namespace.

Source code in geoserver/geoserver.py
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
def create_namespace(self, body: Union[str, Dict[str, Any]]) -> str:
    """Create a new namespace.

    Args:
        body: The body of the request used to create the namespace.

    Returns:
        The created namespace.
    """
    url = f"{self.service_url}/rest/namespaces"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_namespace

get_namespace(
    name: str, *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_namespace(name: str, *, format: Literal['xml']) -> str
get_namespace(
    name: str, *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Get an individual namespace.

Parameters:

Name Type Description Default
name str

The name of the namespace.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested namespace.

Source code in geoserver/geoserver.py
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
def get_namespace(self, name: str, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Get an individual namespace.

    Args:
        name: The name of the namespace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The requested namespace.
    """
    url = f"{self.service_url}/rest/namespaces/{name}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_namespace

update_namespace(
    name: str, body: Union[str, Dict[str, Any]]
) -> str

Update an individual namespace.

Parameters:

Name Type Description Default
name str

The name of the namespace.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the namespace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
def update_namespace(self, name: str, body: Union[str, Dict[str, Any]]) -> str:
    """Update an individual namespace.

    Args:
        name: The name of the namespace.
        body: The body of the request used to modify the namespace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/namespaces/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_namespace

delete_namespace(name: str) -> str

Delete an individual namespace.

Parameters:

Name Type Description Default
name str

The name of the namespace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
def delete_namespace(self, name: str) -> str:
    """Delete an individual namespace.

    Args:
        name: The name of the namespace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/namespaces/{name}"
    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wms_settings

get_wms_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wms_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_wms_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get the WMS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMS settings for the workspace.

Source code in geoserver/geoserver.py
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
def get_wms_settings(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Get the WMS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMS settings for the workspace.
    """
    url = f"{self.service_url}/rest/services/wms/settings.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wms/workspaces/{workspace}/settings.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wms_settings

update_wms_settings(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Update the WMS settings for the workspace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the WMS settings.

required
workspace Optional[str]

The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
def update_wms_settings(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Update the WMS settings for the workspace.

    Args:
        body: The body of the request used to modify the WMS settings.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wms/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wms/workspaces/{workspace}/settings"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wms_settings

delete_wms_settings(
    *, workspace: Optional[str] = None
) -> str

Delete the WMS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
def delete_wms_settings(self, *, workspace: Optional[str] = None) -> str:
    """Delete the WMS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wms/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wms/workspaces/{workspace}/settings"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wfs_settings

get_wfs_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wfs_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_wfs_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get the WFS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WFS settings for the workspace.

Source code in geoserver/geoserver.py
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
def get_wfs_settings(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Get the WFS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WFS settings for the workspace.
    """
    url = f"{self.service_url}/rest/services/wfs/settings.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wfs/workspaces/{workspace}/settings.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wfs_settings

update_wfs_settings(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Update the WFS settings for the workspace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the WFS settings.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
def update_wfs_settings(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Update the WFS settings for the workspace.

    Args:
        body: The body of the request used to modify the WFS settings.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wfs/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wfs/workspaces/{workspace}/settings"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wfs_settings

delete_wfs_settings(
    *, workspace: Optional[str] = None
) -> str

Delete the WFS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
def delete_wfs_settings(self, *, workspace: Optional[str] = None) -> str:
    """Delete the WFS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wfs/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wfs/workspaces/{workspace}/settings"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wcs_settings

get_wcs_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wcs_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_wcs_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get the WCS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WCS settings for the workspace.

Source code in geoserver/geoserver.py
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
def get_wcs_settings(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Get the WCS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WCS settings for the workspace.
    """
    url = f"{self.service_url}/rest/services/wcs/settings.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wcs/workspaces/{workspace}/settings.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wcs_settings

update_wcs_settings(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Update the WCS settings for the workspace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the WCS settings.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
def update_wcs_settings(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Update the WCS settings for the workspace.

    Args:
        body: The body of the request used to modify the WCS settings.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wcs/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wcs/workspaces/{workspace}/settings"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wcs_settings

delete_wcs_settings(
    *, workspace: Optional[str] = None
) -> str

Delete the WCS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
def delete_wcs_settings(self, *, workspace: Optional[str] = None) -> str:
    """Delete the WCS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wcs/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wcs/workspaces/{workspace}/settings"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wmts_settings

get_wmts_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wmts_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_wmts_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Get the WMTS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMTS settings for the workspace.

Source code in geoserver/geoserver.py
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
def get_wmts_settings(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Get the WMTS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMTS settings for the workspace.
    """
    url = f"{self.service_url}/rest/services/wmts/settings.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wmts/workspaces/{workspace}/settings.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wmts_settings

update_wmts_settings(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Update the WMTS settings for the workspace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the WMTS settings.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
def update_wmts_settings(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Update the WMTS settings for the workspace.

    Args:
        body: The body of the request used to modify the WMTS settings.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wmts/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wmts/workspaces/{workspace}/settings"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wmts_settings

delete_wmts_settings(
    *, workspace: Optional[str] = None
) -> str

Delete the WMTS settings for the workspace.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
def delete_wmts_settings(self, *, workspace: Optional[str] = None) -> str:
    """Delete the WMTS settings for the workspace.

    Args:
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/wmts/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/services/wmts/workspaces/{workspace}/settings"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_oseo_settings

get_oseo_settings(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_oseo_settings(*, format: Literal['xml']) -> str
get_oseo_settings(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Retrieves Open Search for Earth Observation Service settings globally for the server.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The OSEO settings for the workspace.

Source code in geoserver/geoserver.py
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
def get_oseo_settings(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Retrieves Open Search for Earth Observation Service settings globally for the server.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The OSEO settings for the workspace.
    """
    url = f"{self.service_url}/rest/services/oseo/settings.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_oseo_settings

update_oseo_settings(
    body: Union[str, Dict[str, Any]],
) -> str

Update the Open Search for Earth Observation Service settings globally for the server.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the OSEO settings.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
def update_oseo_settings(self, body: Union[str, Dict[str, Any]]) -> str:
    """Update the Open Search for Earth Observation Service settings globally for the server.

    Args:
        body: The body of the request used to modify the OSEO settings.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/services/oseo/settings"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

reset

reset() -> str

Resets all store, raster, and schema caches. This operation is used to force GeoServer to drop all caches and store connections and reconnect to each of them the next time they are needed by a request. This is useful in case the stores themselves cache some information about the data structures they manage that may have changed in the meantime.

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
def reset(self) -> str:
    """Resets all store, raster, and schema caches.
    This operation is used to force GeoServer to drop all caches and store connections and reconnect
    to each of them the next time they are needed by a request.
    This is useful in case the stores themselves cache some information about the data structures
    they manage that may have changed in the meantime.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/reset"
    self._request(method="put", url=url)
    return OK_MESSAGE

reload

reload() -> str

Reloads the GeoServer catalog and configuration from disk. This operation is used in cases where an external tool has modified the on-disk configuration. This operation will also force GeoServer to drop any internal caches and reconnect to all data stores.

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
def reload(self) -> str:
    """Reloads the GeoServer catalog and configuration from disk.
    This operation is used in cases where an external tool has modified the on-disk configuration.
    This operation will also force GeoServer to drop any internal caches and reconnect to all data stores.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/reload"
    self._request(method="put", url=url)
    return OK_MESSAGE

get_resource

get_resource(
    path: str,
    *,
    operation: Literal["default", "metadata"] = "default",
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_resource(
    path: str,
    *,
    operation: Literal["default", "metadata"] = "default",
    format: Literal["xml"],
) -> str
get_resource(
    path: str,
    *,
    operation: Literal["default", "metadata"] = "default",
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Download a resource, list contents of directory, or show formatted resource metadata. Response content depends upon parameters. With operation=default, if the request is made against a non-directory resource, the content of the resource is returned.

Parameters:

Name Type Description Default
path str

The path to the resource.

required
operation Literal['default', 'metadata']

Optional. The type of resource to get. It can be either "default" or "metadata". Defaults to "default".

'default'
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The requested resource.

Example
geoserver.get_resource(resource="styles/default_point.sld", operation="default")
Source code in geoserver/geoserver.py
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
def get_resource(
    self,
    path: str,
    *,
    operation: Literal["default", "metadata"] = "default",
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Download a resource, list contents of directory, or show formatted resource metadata.
    Response content depends upon parameters.
    With operation=default, if the request is made against a non-directory resource, the content of the resource is returned.

    Args:
        path: The path to the resource.
        operation: Optional. The type of resource to get. It can be either "default" or "metadata". Defaults to "default".
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The requested resource.

    Example:
        ```python
        geoserver.get_resource(resource="styles/default_point.sld", operation="default")
        ```
    """
    url = f"{self.service_url}/rest/resource/{path}"
    params = dict(operation=operation, format="json")
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

update_resource

update_resource(
    path: str, body: Union[str, Dict[str, Any]]
) -> str

Upload/move/copy a resource, create directories on the fly (overwrite if exists). For move/copy operations, place source path in body. Copying is not supported for directories.

Parameters:

Name Type Description Default
path str

The path to the resource.

required
body Union[str, Dict[str, Any]]

The content of the resource to upload. In the case of a move or copy operation, this is instead the path to the source resource to move/copy from.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
def update_resource(self, path: str, body: Union[str, Dict[str, Any]]) -> str:
    """Upload/move/copy a resource, create directories on the fly (overwrite if exists). For move/copy operations, place source path in body. Copying is not supported for directories.

    Args:
        path: The path to the resource.
        body: The content of the resource to upload. In the case of a move or copy operation,
            this is instead the path to the source resource to move/copy from.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/resource/{path}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_resource

delete_resource(path: str) -> str

Delete a resource (recursively if directory)

Parameters:

Name Type Description Default
path str

The full path to the resource. Required, but may be empty; a request to /resource references the top level resource directory.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
def delete_resource(self, path: str) -> str:
    """Delete a resource (recursively if directory)

    Args:
        path: The full path to the resource. Required, but may be empty; a request to /resource references the top level resource directory.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/resource/{path}"
    self._request(method="delete", url=url)
    return DELETED_MESSAGE

resource_exists

resource_exists(path: str) -> bool

Check if a resource exists.

Parameters:

Name Type Description Default
path str

The full path to the resource.

required

Returns:

Type Description
bool

Success message.

Source code in geoserver/geoserver.py
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
def resource_exists(self, path: str) -> bool:
    """Check if a resource exists.

    Args:
        path: The full path to the resource.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/resource/{path}"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

get_master_password

get_master_password(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_master_password(*, format: Literal['xml']) -> str
get_master_password(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays the keystore password. HTTPS is strongly suggested, otherwise password will be sent in plain text.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The master password.

Source code in geoserver/geoserver.py
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
def get_master_password(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays the keystore password. HTTPS is strongly suggested, otherwise password will be sent in plain text.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The master password.
    """
    url = f"{self.service_url}/rest/security/masterpw.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_master_password

update_master_password(
    body: Union[str, Dict[str, Any]],
) -> str

Changes keystore password. Must supply current keystore password. HTTPS is strongly suggested, otherwise password will be sent in plain text.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to set the master password.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
def update_master_password(self, body: Union[str, Dict[str, Any]]) -> str:
    """Changes keystore password. Must supply current keystore password. HTTPS is strongly suggested, otherwise password will be sent in plain text.

    Args:
        body: The body of the request used to set the master password.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/masterpw"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

update_password

update_password(body: Union[str, Dict[str, Any]]) -> str

Updates the password for the account used to issue the request.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to set the password.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
def update_password(self, body: Union[str, Dict[str, Any]]) -> str:
    """Updates the password for the account used to issue the request.

    Args:
        body: The body of the request used to set the password.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/self/password"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

get_catalog_mode

get_catalog_mode(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_catalog_mode(*, format: Literal['xml']) -> str
get_catalog_mode(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Gets the catalog mode, which specifies how GeoServer will advertise secured layers and behave when a secured layer is accessed without the necessary privileges.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The catalog mode.

Source code in geoserver/geoserver.py
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
def get_catalog_mode(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Gets the catalog mode, which specifies how GeoServer will advertise secured layers
    and behave when a secured layer is accessed without the necessary privileges.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The catalog mode.
    """
    url = f"{self.service_url}/rest/security/acl/catalog.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_catalog_mode

update_catalog_mode(
    body: Union[str, Dict[str, Any]],
) -> str

Changes catalog mode. The mode must be one of HIDE, MIXED, or CHALLENGE.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The catalog mode information to upload.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
def update_catalog_mode(self, body: Union[str, Dict[str, Any]]) -> str:
    """Changes catalog mode. The mode must be one of HIDE, MIXED, or CHALLENGE.

    Args:
        body: The catalog mode information to upload.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/catalog"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

get_security_layers

get_security_layers(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_security_layers(*, format: Literal['xml']) -> str
get_security_layers(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays the current layer-based security rules.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The security layers.

Source code in geoserver/geoserver.py
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
def get_security_layers(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays the current layer-based security rules.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The security layers.
    """
    url = f"{self.service_url}/rest/security/acl/layers.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

security_layer_exists

security_layer_exists(rule: str) -> bool

Check if a security layer exists.

Parameters:

Name Type Description Default
rule str

The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

required

Returns:

Type Description
bool

Success message.

Source code in geoserver/geoserver.py
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
def security_layer_exists(self, rule: str) -> bool:
    """Check if a security layer exists.

    Args:
        rule: The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/layers/{rule}"
    response = self._request(method="head", url=url, ignore=[404, 405])
    return response.status_code == 200

create_security_layers

create_security_layers(
    body: Union[str, Dict[str, Any]],
) -> str

Adds one or more new layer-based rules to the list of security rules.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the security layer.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
def create_security_layers(self, body: Union[str, Dict[str, Any]]) -> str:
    """Adds one or more new layer-based rules to the list of security rules.

    Args:
        body: The body of the request used to create the security layer.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/layers"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

update_security_layers

update_security_layers(
    body: Union[str, Dict[str, Any]],
) -> str

Updates one or more layer-based security rules.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the security layer.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
def update_security_layers(self, body: Union[str, Dict[str, Any]]) -> str:
    """Updates one or more layer-based security rules.

    Args:
        body: The body of the request used to modify the security layer.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/layers"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_security_layer

delete_security_layer(rule: Optional[str] = None) -> str

Removes one or more layer-based security rules from the list of security rules. The rule must specified in the last part of the URL and of the form ..[r|w|a]

Parameters:

Name Type Description Default
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
def delete_security_layer(self, rule: Optional[str] = None) -> str:
    """Removes one or more layer-based security rules from the list of security rules.
    The `rule` must specified in the last part of the URL and of the form <workspace>.<layer>.[r|w|a]

    Args:
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/layers"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/layers/{rule}"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_security_services

get_security_services(
    *,
    rule: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_security_services(
    *, rule: Optional[str] = None, format: Literal["xml"]
) -> str
get_security_services(
    *,
    rule: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays the current service-based security rules.

Parameters:

Name Type Description Default
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The security services.

Source code in geoserver/geoserver.py
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
def get_security_services(
    self, *, rule: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays the current service-based security rules.

    Args:
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The security services.
    """
    url = f"{self.service_url}/rest/security/acl/services.{format}"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/services/{rule}.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_security_services

update_security_services(
    body: Union[str, Dict[str, Any]],
    *,
    rule: Optional[str] = None,
) -> str

Adds one or more new service-based rules to the list of security rules.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the security services.

required
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
def update_security_services(self, body: Union[str, Dict[str, Any]], *, rule: Optional[str] = None) -> str:
    """Adds one or more new service-based rules to the list of security rules.

    Args:
        body: The body of the request used to create the security services.
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/services"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/services/{rule}"

    self._request(method="post", url=url, body=body)
    return UPDATED_MESSAGE

delete_security_services

delete_security_services(
    *, rule: Optional[str] = None
) -> str

Removes one or more service-based security rules from the list of security rules.

Parameters:

Name Type Description Default
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
def delete_security_services(self, *, rule: Optional[str] = None) -> str:
    """Removes one or more service-based security rules from the list of security rules.

    Args:
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/services"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/services/{rule}"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_security_access

get_security_access(
    *,
    rule: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_security_access(
    *, rule: Optional[str] = None, format: Literal["xml"]
) -> str
get_security_access(
    *,
    rule: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays the current REST access rules.

Parameters:

Name Type Description Default
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The security REST.

Source code in geoserver/geoserver.py
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
def get_security_access(
    self, *, rule: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays the current REST access rules.

    Args:
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The security REST.
    """
    url = f"{self.service_url}/rest/security/acl/rest.{format}"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/{rule}.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

create_security_access

create_security_access(
    body: Union[str, Dict[str, Any]],
    *,
    rule: Optional[str] = None,
) -> str

Adds one or more new REST access rules.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the security access.

required
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
def create_security_access(self, body: Union[str, Dict[str, Any]], *, rule: Optional[str] = None) -> str:
    """Adds one or more new REST access rules.

    Args:
        body: The body of the request used to create the security access.
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/rest"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/{rule}"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

update_security_access

update_security_access(
    body: Union[str, Dict[str, Any]],
    *,
    rule: Optional[str] = None,
) -> str

Updates one or more REST access rules.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the security access.

required
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
def update_security_access(self, body: Union[str, Dict[str, Any]], *, rule: Optional[str] = None) -> str:
    """Updates one or more REST access rules.

    Args:
        body: The body of the request used to modify the security access.
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/rest"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/{rule}"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_security_access

delete_security_access(
    body: Union[str, Dict[str, Any]],
    *,
    rule: Optional[str] = None,
) -> str

Removes one or more REST access rules.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to delete the security access.

required
rule Optional[str]

Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/..r

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
def delete_security_access(self, body: Union[str, Dict[str, Any]], *, rule: Optional[str] = None) -> str:
    """Removes one or more REST access rules.

    Args:
        body: The body of the request used to delete the security access.
        rule: Optional. The specified rule, as the last part in the URI, e.g. /security/acl/layers/*.*.r

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/acl/rest"
    if rule is not None:
        url = f"{self.service_url}/rest/security/acl/{rule}"

    self._request(method="delete", url=url, body=body)
    return DELETED_MESSAGE

get_settings

get_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_settings(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays a list of all global or workspace settings on the server.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The settings for the workspace.

Source code in geoserver/geoserver.py
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
def get_settings(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays a list of all global or workspace settings on the server.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The settings for the workspace.
    """
    url = f"{self.service_url}/rest/settings.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/settings.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_settings

update_settings(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: Optional[str] = None,
) -> str

Updates global or workspace settings on the server.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to modify the settings.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
def update_settings(self, body: Union[str, Dict[str, Any]], *, workspace: Optional[str] = None) -> str:
    """Updates global or workspace settings on the server.

    Args:
        body: The body of the request used to modify the settings.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/settings"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/settings"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_settings

delete_settings(*, workspace: str) -> str

Deletes workspace settings on the server.

Parameters:

Name Type Description Default
workspace str

Optional. The name of the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
def delete_settings(self, *, workspace: str) -> str:
    """Deletes workspace settings on the server.

    Args:
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/settings"
    response = self._request(method="delete", url=url)
    return response.text

get_contact_settings

get_contact_settings(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays a list of all global contact settings on the server. This is a subset of what is available at the /settings endpoint.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The contact settings.

Source code in geoserver/geoserver.py
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
def get_contact_settings(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays a list of all global contact settings on the server.
    This is a subset of what is available at the /settings endpoint.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The contact settings.
    """
    url = f"{self.service_url}/rest/settings/contact.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_contact_settings

update_contact_settings() -> str

Updates global contact settings on the server.

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2827
2828
2829
2830
2831
2832
2833
2834
2835
def update_contact_settings(self) -> str:
    """Updates global contact settings on the server.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/settings/contact"
    self._request(method="put", url=url)
    return UPDATED_MESSAGE

get_coverage_granules

get_coverage_granules(
    name: str,
    *,
    workspace: str,
    store: str,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_coverage_granules(
    name: str,
    *,
    workspace: str,
    store: str,
    format: Literal["xml"],
) -> str
get_coverage_granules(
    name: str,
    *,
    workspace: str,
    store: str,
    limit: int = -1,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays a list of all the attributes associated to a particular coverage's granules

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace containing the coverage stores.

required
store str

The name of the store.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The granules in the structured coverage store.

Source code in geoserver/geoserver.py
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
def get_coverage_granules(
    self, name: str, *, workspace: str, store: str, limit: int = -1, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays a list of all the attributes associated to a particular coverage's granules

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace containing the coverage stores.
        store: The name of the store.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The granules in the structured coverage store.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}/index/granules.{format}"
    params = dict(limit=limit) if limit >= 0 else {}
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

delete_coverage_granules

delete_coverage_granules(
    name: str,
    *,
    workspace: str,
    store: str,
    filter: str = "",
    purge: Literal["none", "metadata", "all"] = "none",
    update_bbox: bool = False,
) -> str

Allows removing one or more granules from the index.

Parameters:

Name Type Description Default
name str

The name of the coverage.

required
workspace str

The name of the workspace containing the coverage stores.

required
store str

The name of the store.

required
filter str

Optional. A CQL filter to reduce the returned granules.

''
purge Literal['none', 'metadata', 'all']

Optional. The purge parameter specifies if and how the underlying raster data source is deleted. Allowable values for this parameter are none, metadata and all. When set to none data and auxiliary files are preserved, only the registration in the mosaic is removed When set to metadata delete only auxiliary files and metadata (e.g. NetCDF sidecar indexes). It's recommended when data files (such as granules) should not be deleted from disk. Finally, when set to all both data and auxiliary files are removed.

'none'
update_bbox bool

Optional. When set to True, triggers re-calculation of the layer native bbox. Defaults to False.

False

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
def delete_coverage_granules(
    self,
    name: str,
    *,
    workspace: str,
    store: str,
    filter: str = "",
    purge: Literal["none", "metadata", "all"] = "none",
    update_bbox: bool = False,
) -> str:
    """Allows removing one or more granules from the index.

    Args:
        name: The name of the coverage.
        workspace: The name of the workspace containing the coverage stores.
        store: The name of the store.
        filter: Optional. A CQL filter to reduce the returned granules.
        purge: Optional. The purge parameter specifies if and how the underlying raster data source is deleted.
            Allowable values for this parameter are `none`, `metadata` and `all`. When set to `none` data and auxiliary files are preserved,
            only the registration in the mosaic is removed When set to `metadata` delete only auxiliary files and metadata
            (e.g. NetCDF sidecar indexes). It's recommended when data files (such as granules) should not be deleted from disk.
            Finally, when set to `all` both data and auxiliary files are removed.
        update_bbox: Optional. When set to True, triggers re-calculation of the layer native bbox. Defaults to False.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{name}/index/granules"
    params = dict(filter=filter, purge=purge, updateBBox=update_bbox)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

get_coverages_granule

get_coverages_granule(
    name: str,
    *,
    workspace: str,
    store: str,
    coverage: str,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_coverages_granule(
    name: str,
    *,
    workspace: str,
    store: str,
    coverage: str,
    format: Literal["xml"],
) -> str
get_coverages_granule(
    name: str,
    *,
    workspace: str,
    store: str,
    coverage: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays a list of all the attributes associated to a particular coverage's granule

Parameters:

Name Type Description Default
name str

The ID of the granule.

required
workspace str

The name of the workspace containing the coverage stores.

required
store str

The name of the store.

required
coverage str

The name of the coverage.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The granule in the structured coverage store.

Source code in geoserver/geoserver.py
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
def get_coverages_granule(
    self, name: str, *, workspace: str, store: str, coverage: str, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays a list of all the attributes associated to a particular coverage's granule

    Args:
        name: The ID of the granule.
        workspace: The name of the workspace containing the coverage stores.
        store: The name of the store.
        coverage: The name of the coverage.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The granule in the structured coverage store.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{coverage}/granules/index/{name}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

delete_coverage_granule

delete_coverage_granule(
    name: str,
    *,
    workspace: str,
    store: str,
    coverage: str,
    purge: bool = False,
    update_bbox: bool = False,
) -> str

Allows removing the specified granule.

Parameters:

Name Type Description Default
name str

The ID of the granule.

required
workspace str

The name of the workspace containing the coverage stores.

required
store str

The name of the store.

required
coverage str

The name of the coverage.

required
purge bool

Optional. The purge parameter specifies if and how the underlying raster data source is deleted. Allowable values for this parameter are none, metadata and all. When set to none data and auxiliary files are preserved, only the registration in the mosaic is removed When set to metadata delete only auxiliary files and metadata (e.g. NetCDF sidecar indexes). It's recommended when data files (such as granules) should not be deleted from disk. Finally, when set to all both data and auxiliary files are removed.

False
update_bbox bool

Optional. When set to True, triggers re-calculation of the layer native bbox. Defaults to False.

False

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
def delete_coverage_granule(
    self, name: str, *, workspace: str, store: str, coverage: str, purge: bool = False, update_bbox: bool = False
) -> str:
    """Allows removing the specified granule.

    Args:
        name: The ID of the granule.
        workspace: The name of the workspace containing the coverage stores.
        store: The name of the store.
        coverage: The name of the coverage.
        purge: Optional. The purge parameter specifies if and how the underlying raster data source is deleted.
            Allowable values for this parameter are `none`, `metadata` and `all`. When set to `none` data and auxiliary files are preserved,
            only the registration in the mosaic is removed When set to `metadata` delete only auxiliary files and metadata
            (e.g. NetCDF sidecar indexes). It's recommended when data files (such as granules) should not be deleted from disk.
            Finally, when set to `all` both data and auxiliary files are removed.
        update_bbox: Optional. When set to True, triggers re-calculation of the layer native bbox. Defaults to False.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{store}/coverages/{coverage}/granules/index/{name}"
    params = dict(purge=purge, updateBBox=update_bbox)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

get_styles

get_styles(
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_styles(
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_styles(
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays a list of all styles on the server.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The styles.

Source code in geoserver/geoserver.py
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
def get_styles(
    self, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays a list of all styles on the server.

    Args:
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The styles.
    """
    url = f"{self.service_url}/rest/styles.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

style_exists

style_exists(
    name: str, *, workspace: Optional[str] = None
) -> bool

Check if a style exists.

Parameters:

Name Type Description Default
name str

The name of the style.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
bool

True if the style exists, False otherwise.

Source code in geoserver/geoserver.py
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
def style_exists(self, name: str, *, workspace: Optional[str] = None) -> bool:
    """Check if a style exists.

    Args:
        name: The name of the style.
        workspace: Optional. The name of the workspace.

    Returns:
        True if the style exists, False otherwise.
    """
    url = f"{self.service_url}/rest/styles/{name}.xml"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

get_style

get_style(
    name: str,
    *,
    workspace: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_style(
    name: str,
    *,
    workspace: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_style(
    name: str,
    *,
    workspace: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves a single style.

Parameters:

Name Type Description Default
name str

The name of the style.

required
workspace Optional[str]

Optional. The name of the workspace.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

Success message.

Source code in geoserver/geoserver.py
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
def get_style(
    self, name: str, *, workspace: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Retrieves a single style.

    Args:
        name: The name of the style.
        workspace: Optional. The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/styles/{name}.{format}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles/{name}.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

create_style

create_style(
    body: str, *, workspace: Optional[str] = None
) -> str

Creates a new style.

Warning

This method only supports body in XML format.

Parameters:

Name Type Description Default
body str

The body of the request used to create the style.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Example
geoserver.create_style(body="<sld>...</sld>")
Source code in geoserver/geoserver.py
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
def create_style(self, body: str, *, workspace: Optional[str] = None) -> str:
    """Creates a new style.

    Warning:
        This method only supports body in XML format.

    Args:
        body: The body of the request used to create the style.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.

    Example:
        ```python
        geoserver.create_style(body="<sld>...</sld>")
        ```
    """
    url = f"{self.service_url}/rest/styles"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

upload_style

upload_style(
    file: Union[str, Path, IO[bytes]],
    *,
    name: str,
    workspace: Optional[str] = None,
    overwrite: Literal[True],
) -> str
upload_style(
    file: Union[str, Path, IO[bytes]],
    *,
    name: Optional[str] = None,
    workspace: Optional[str] = None,
    overwrite: Literal[False] = False,
) -> str
upload_style(
    file: Union[str, Path, IO[bytes]],
    *,
    name: Optional[str] = None,
    workspace: Optional[str] = None,
    overwrite: bool = False,
) -> str

Uploads a style from an SLD file, a ZIP file (an SLD file with its icons), a file object or SLD content.

Note

The name parameter is inferred from the file name when file is a path or a file object opened from a path. It is required otherwise.

Parameters:

Name Type Description Default
file Union[str, Path, IO[bytes]]

The path to an SLD or ZIP file, a binary file object (e.g. open(path, "rb") or io.BytesIO), or the SLD content itself as a string.

required
name Optional[str]

Optional. The name of the style. Required if overwrite is True.

None
workspace Optional[str]

Optional. The name of the workspace.

None
overwrite bool

Optional. Whether to replace the content of an existing style. Uploading a style that already exists without overwrite=True raises an error. Defaults to False.

False

Returns:

Type Description
str

Success message.

Example

To upload a style from a local SLD or ZIP file, named after the file:

geoserver.upload_style("path/to/my_style.sld", workspace="demo")

To upload a style generated in Python:

sld = "<StyledLayerDescriptor version="1.0.0" ...>...</StyledLayerDescriptor>"
geoserver.upload_style(sld, name="my_style", workspace="demo")

To replace the content of an existing style:

geoserver.upload_style("path/to/my_style.sld", name="my_style", workspace="demo", overwrite=True)
Source code in geoserver/geoserver.py
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
def upload_style(
    self,
    file: Union[str, Path, IO[bytes]],
    *,
    name: Optional[str] = None,
    workspace: Optional[str] = None,
    overwrite: bool = False,
) -> str:
    """Uploads a style from an SLD file, a ZIP file (an SLD file with its icons), a file object or SLD content.

    Note:
        The `name` parameter is inferred from the file name when `file` is a path or a file object opened from a
        path. It is required otherwise.

    Args:
        file: The path to an SLD or ZIP file, a binary file object (e.g. `open(path, "rb")` or `io.BytesIO`),
            or the SLD content itself as a string.
        name: Optional. The name of the style. Required if `overwrite` is `True`.
        workspace: Optional. The name of the workspace.
        overwrite: Optional. Whether to replace the content of an existing style. Uploading a style that already
            exists without `overwrite=True` raises an error. Defaults to False.

    Returns:
        Success message.

    Example:
        To upload a style from a local SLD or ZIP file, named after the file:

        ```python
        geoserver.upload_style("path/to/my_style.sld", workspace="demo")
        ```

        To upload a style generated in Python:

        ```python
        sld = "<StyledLayerDescriptor version=\"1.0.0\" ...>...</StyledLayerDescriptor>"
        geoserver.upload_style(sld, name="my_style", workspace="demo")
        ```

        To replace the content of an existing style:

        ```python
        geoserver.upload_style("path/to/my_style.sld", name="my_style", workspace="demo", overwrite=True)
        ```
    """
    if overwrite and name is None:
        raise ValueError("The `name` argument must be provided when `overwrite` is `True`.")
    if isinstance(file, Path):
        file = file.as_posix()

    is_content = isinstance(file, str) and file.lstrip().startswith("<")
    if name is None and not is_content:
        local_name = file_name(file)
        name = Path(local_name).stem if local_name is not None else None
    if name is None:
        raise ValueError("The `name` argument must be provided, either as an argument or as the file name.")

    url = f"{self.service_url}/rest/styles"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles"

    # Upload from a zip file
    if not is_content and is_zip(file):
        headers = {"Content-Type": "application/zip"}
        if overwrite:
            self._request(method="put", url=f"{url}/{name}", file=file, headers=headers)
        else:
            self._request(method="post", url=url, file=file, params=dict(name=name), headers=headers)
        return CREATED_MESSAGE

    # Upload from SLD content
    if is_content:
        sld = str(file)
    elif isinstance(file, str):
        sld = Path(file).read_text(encoding="utf-8")
    else:
        content = file.read()
        sld = content.decode("utf-8") if isinstance(content, bytes) else content

    if overwrite:
        self.update_style(name, body=sld, workspace=workspace)
    else:
        headers = {"Content-Type": self._sld_content_type(sld)}
        self._request(method="post", url=url, body=sld, params=dict(name=name), headers=headers)
    return CREATED_MESSAGE

update_style

update_style(
    name: str, body: str, *, workspace: Optional[str] = None
) -> str

Updates a single style.

Warning

This method only supports body in XML format.

Parameters:

Name Type Description Default
name str

The name of the style.

required
body str

The content of the updated style, in XML format.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
def update_style(self, name: str, body: str, *, workspace: Optional[str] = None) -> str:
    """Updates a single style.

    Warning:
        This method only supports body in XML format.

    Args:
        name: The name of the style.
        body: The content of the updated style, in XML format.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/styles/{name}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles/{name}"

    self._request(method="put", url=url, body=body, headers={"Content-Type": self._sld_content_type(body)})
    return UPDATED_MESSAGE

download_style

download_style(
    name: str, *, workspace: Optional[str] = None
) -> str

Downloads a single style.

Parameters:

Name Type Description Default
name str

The name of the style.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

The style content.

Source code in geoserver/geoserver.py
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
def download_style(self, name: str, *, workspace: Optional[str] = None) -> str:
    """Downloads a single style.

    Args:
        name: The name of the style.
        workspace: Optional. The name of the workspace.

    Returns:
        The style content.
    """
    url = f"{self.service_url}/rest/styles/{name}.sld"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles/{name}.sld"

    response = self._request(method="get", url=url)
    return response.text

publish_style

publish_style(
    layer: str,
    style: str,
    *,
    workspace: Optional[str] = None,
) -> str

Publishes a style to a layer. This is equivalent to setting the default style for a layer, which will apply the style to the layer when it is rendered.

Note

This method is equivalent to updating the layer with the default style.

Parameters:

Name Type Description Default
layer str

The name of the layer.

required
style str

The name of the style.

required
workspace Optional[str]

Optional. The name of the workspace.

None

Returns:

Type Description
str

Success message.

Example

First, make sure the layer and style exist. Then, publish the style to the layer:

geoserver.publish_style(layer="my_layer", style="my_style", workspace="demo")
Source code in geoserver/geoserver.py
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
def publish_style(self, layer: str, style: str, *, workspace: Optional[str] = None) -> str:
    """Publishes a style to a layer. This is equivalent to setting the default style for a layer,
    which will apply the style to the layer when it is rendered.

    Note:
        This method is equivalent to updating the layer with the default style.

    Args:
        layer: The name of the layer.
        style: The name of the style.
        workspace: Optional. The name of the workspace.

    Returns:
        Success message.

    Example:
        First, make sure the layer and style exist.
        Then, publish the style to the layer:

        ```python
        geoserver.publish_style(layer="my_layer", style="my_style", workspace="demo")
        ```

    """
    url = f"{self.service_url}/rest/layers/{layer}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{layer}"

    body = f"<layer><defaultStyle><name>{style}</name></defaultStyle></layer>"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_style

delete_style(
    name: str,
    *,
    workspace: Optional[str] = None,
    purge: bool = False,
    recurse: bool = False,
) -> str

Deletes a single style.

Parameters:

Name Type Description Default
name str

The name of the style.

required
workspace Optional[str]

Optional. The name of the workspace.

None
purge bool

Optional. Whether to purge the style from the catalog. Defaults to False.

False
recurse bool

Optional. Whether to delete references to the style. Defaults to False.

False

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
def delete_style(
    self, name: str, *, workspace: Optional[str] = None, purge: bool = False, recurse: bool = False
) -> str:
    """Deletes a single style.

    Args:
        name: The name of the style.
        workspace: Optional. The name of the workspace.
        purge: Optional. Whether to purge the style from the catalog. Defaults to False.
        recurse: Optional. Whether to delete references to the style. Defaults to False.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/styles/{name}"
    if workspace is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/styles/{name}"

    params = dict(purge=purge, recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

get_templates

get_templates(
    *,
    workspace: Optional[str] = None,
    store: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_templates(
    *,
    workspace: Optional[str] = None,
    store: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_templates(
    *,
    workspace: Optional[str] = None,
    store: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Displays a list of all templates on the server.

Parameters:

Name Type Description Default
workspace Optional[str]

Optional. The name of the workspace.

None
store Optional[str]

Optional. The name of the store.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The templates.

Source code in geoserver/geoserver.py
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
def get_templates(
    self, *, workspace: Optional[str] = None, store: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Displays a list of all templates on the server.

    Args:
        workspace: Optional. The name of the workspace.
        store: Optional. The name of the store.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The templates.
    """
    if workspace is None and store is None:
        url = f"{self.service_url}/rest/templates.{format}"
    elif workspace is not None and store is None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/templates.{format}"
    elif workspace is not None and store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{store}/templates.{format}"
    else:
        raise ValueError("A workspace must be provided if a store is provided.")

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

get_template

get_template(
    name: str,
    *,
    workspace: Optional[str] = None,
    data_store: Optional[str] = None,
    feature_type: Optional[str] = None,
    coverage_store: Optional[str] = None,
    coverage: Optional[str] = None,
) -> str

Displays a list of all templates on the server.

Parameters:

Name Type Description Default
name str

The name of the template.

required
workspace Optional[str]

Optional. The name of the workspace.

None
data_store Optional[str]

Optional. The name of the datastore.

None
feature_type Optional[str]

Optional. The name of the featuretype.

None
coverage_store Optional[str]

Optional. The name of the coveragestore.

None
coverage Optional[str]

Optional. The name of the coverage.

None

Returns:

Type Description
str

The templates.

Source code in geoserver/geoserver.py
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
def get_template(
    self,
    name: str,
    *,
    workspace: Optional[str] = None,
    data_store: Optional[str] = None,
    feature_type: Optional[str] = None,
    coverage_store: Optional[str] = None,
    coverage: Optional[str] = None,
) -> str:
    """Displays a list of all templates on the server.

    Args:
        name: The name of the template.
        workspace: Optional. The name of the workspace.
        data_store: Optional. The name of the datastore.
        feature_type: Optional. The name of the featuretype.
        coverage_store: Optional. The name of the coveragestore.
        coverage: Optional. The name of the coverage.

    Returns:
        The templates.
    """
    if (
        workspace is None
        and data_store is None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/templates/{name}.ftl"
    if (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is not None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{data_store}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is not None
        and feature_type is not None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{data_store}/featuretypes/{feature_type}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is not None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{coverage_store}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is not None
        and coverage is not None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{coverage_store}/coverages/{coverage}/templates/{name}.ftl"
    else:
        raise ValueError(
            f"Invalid combinations of workspace, store, and featuretype. Got {workspace}, {data_store}, and {feature_type}."
        )

    response = self._request(method="get", url=url)
    return response.json()

create_template

create_template(
    name: str,
    body: str,
    *,
    workspace: Optional[str] = None,
    data_store: Optional[str] = None,
    feature_type: Optional[str] = None,
    coverage_store: Optional[str] = None,
    coverage: Optional[str] = None,
) -> str

Inserts or updates a single template registered for use in a workspace (example for GetFeatureInfo WMS operation). Overwrites any existing template with the same name and location.

Parameters:

Name Type Description Default
name str

The name of the template.

required
body str

The body of the request used to modify the template.

required
workspace Optional[str]

Optional. The name of the workspace.

None
data_store Optional[str]

Optional. The name of the datastore.

None
feature_type Optional[str]

Optional. The name of the featuretype.

None
coverage_store Optional[str]

Optional. The name of the coveragestore.

None
coverage Optional[str]

Optional. The name of the coverage.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
def create_template(
    self,
    name: str,
    body: str,
    *,
    workspace: Optional[str] = None,
    data_store: Optional[str] = None,
    feature_type: Optional[str] = None,
    coverage_store: Optional[str] = None,
    coverage: Optional[str] = None,
) -> str:
    """Inserts or updates a single template registered for use in a workspace (example for GetFeatureInfo WMS operation).
    Overwrites any existing template with the same name and location.

    Args:
        name: The name of the template.
        body: The body of the request used to modify the template.
        workspace: Optional. The name of the workspace.
        data_store: Optional. The name of the datastore.
        feature_type: Optional. The name of the featuretype.
        coverage_store: Optional. The name of the coveragestore.
        coverage: Optional. The name of the coverage.

    Returns:
        Success message.
    """
    if (
        workspace is None
        and data_store is None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/templates/{name}.ftl"
    if (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is not None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{data_store}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is not None
        and feature_type is not None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{data_store}/featuretypes/{feature_type}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is not None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{coverage_store}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is not None
        and coverage is not None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{coverage_store}/coverages/{coverage}/templates/{name}.ftl"
    else:
        raise ValueError(
            f"Invalid combinations of workspace, store, and featuretype. Got {workspace}, {data_store}, and {feature_type}."
        )

    headers = {"Content-Type": "text/plain"}
    self._request(method="put", url=url, body=body, headers=headers)
    return CREATED_MESSAGE

delete_template

delete_template(
    name: str,
    *,
    workspace: Optional[str] = None,
    data_store: Optional[str] = None,
    feature_type: Optional[str] = None,
    coverage_store: Optional[str] = None,
    coverage: Optional[str] = None,
) -> str

Deletes a single template registered for use on the server.

Parameters:

Name Type Description Default
name str

The name of the template.

required
workspace Optional[str]

Optional. The name of the workspace.

None
data_store Optional[str]

Optional. The name of the datastore.

None
feature_type Optional[str]

Optional. The name of the featuretype.

None
coverage_store Optional[str]

Optional. The name of the coveragestore.

None
coverage Optional[str]

Optional. The name of the coverage.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
def delete_template(
    self,
    name: str,
    *,
    workspace: Optional[str] = None,
    data_store: Optional[str] = None,
    feature_type: Optional[str] = None,
    coverage_store: Optional[str] = None,
    coverage: Optional[str] = None,
) -> str:
    """Deletes a single template registered for use on the server.

    Args:
        name: The name of the template.
        workspace: Optional. The name of the workspace.
        data_store: Optional. The name of the datastore.
        feature_type: Optional. The name of the featuretype.
        coverage_store: Optional. The name of the coveragestore.
        coverage: Optional. The name of the coverage.

    Returns:
        Success message.
    """
    if (
        workspace is None
        and data_store is None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/templates/{name}.ftl"
    if (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is not None
        and feature_type is None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{data_store}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is not None
        and feature_type is not None
        and coverage_store is None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/datastores/{data_store}/featuretypes/{feature_type}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is not None
        and coverage is None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{coverage_store}/templates/{name}.ftl"
    elif (
        workspace is not None
        and data_store is None
        and feature_type is None
        and coverage_store is not None
        and coverage is not None
    ):
        url = f"{self.service_url}/rest/workspaces/{workspace}/coveragestores/{coverage_store}/coverages/{coverage}/templates/{name}.ftl"
    else:
        raise ValueError(
            f"Invalid combinations of workspace, store, and featuretype. Got {workspace}, {data_store}, and {feature_type}."
        )

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wfs_transforms

get_wfs_transforms(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_wfs_transforms(*, format: Literal['xml']) -> str
get_wfs_transforms(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays a list of all the transforms information available on the server.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The XSLT transforms.

Example

To get the list of all the transforms available on the server, you can use the following code:

geoserver.get_transforms()
Source code in geoserver/geoserver.py
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
def get_wfs_transforms(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays a list of all the transforms information available on the server.

    Args:
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The XSLT transforms.

    Example:
        To get the list of all the transforms available on the server, you can use the following code:

        ```python
        geoserver.get_transforms()
        ```
    """
    url = f"{self.service_url}/rest/services/wfs/transforms.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

create_wfs_transform

create_wfs_transform(
    body: Union[str, Dict[str, Any]],
    *,
    source_format: Optional[str] = None,
    output_format: Optional[str] = None,
    output_mime_type: Optional[str] = None,
    file_extension: Optional[str] = None,
) -> str

Adds a new transform to the server. If the content type used is application/xml the server will assume a definition is being posted, and the XSLT will have to be uploaded separately using a PUT request with content type application/xslt+xml against the transformation resource. If the content type used is application/xslt+xml the server will assume the XSLT itself is being posted, and the name, sourceFormat, outputFormat, outputMimeType query parameters will be used to fill in the transform configuration instead.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the transform.

required

Returns:

Type Description
str

Success message.

Example

To add a new transform to the server, you can use the following code:

body = """
<transform>
    <name>test</name>
    <sourceFormat>GML2</sourceFormat>
    <outputFormat>text/xml</outputFormat>
    <outputMimeType>text/xml</outputMimeType>
    <fileExtension>xml</fileExtension>
</transform>
"""

geoserver.create_transform(body)
Source code in geoserver/geoserver.py
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
def create_wfs_transform(
    self,
    body: Union[str, Dict[str, Any]],
    *,
    source_format: Optional[str] = None,
    output_format: Optional[str] = None,
    output_mime_type: Optional[str] = None,
    file_extension: Optional[str] = None,
) -> str:
    """Adds a new transform to the server.
    If the content type used is application/xml the server will assume a definition is being posted,
    and the XSLT will have to be uploaded separately using a PUT request with content type application/xslt+xml against the transformation resource.
    If the content type used is application/xslt+xml the server will assume the XSLT itself is being posted,
    and the name, sourceFormat, outputFormat, outputMimeType query parameters will be used to fill in the transform configuration instead.

    Args:
        body: The body of the request used to create the transform.

    Returns:
        Success message.

    Example:
        To add a new transform to the server, you can use the following code:

        ```python
        body = \"\"\"
        <transform>
            <name>test</name>
            <sourceFormat>GML2</sourceFormat>
            <outputFormat>text/xml</outputFormat>
            <outputMimeType>text/xml</outputMimeType>
            <fileExtension>xml</fileExtension>
        </transform>
        \"\"\"

        geoserver.create_transform(body)
        ```
    """
    url = f"{self.service_url}/rest/services/wfs/transforms"
    params = dict(
        sourceFormat=source_format,
        outputFormat=output_format,
        outputMimeType=output_mime_type,
        fileExtension=file_extension,
    )
    self._request(method="post", url=url, body=body, params=params)
    return CREATED_MESSAGE

get_wfs_transform

get_wfs_transform(
    name: str, *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_wfs_transform(
    name: str, *, format: Literal["xml"]
) -> str
get_wfs_transform(
    name: str, *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Retrieves a single transformation.

Parameters:

Name Type Description Default
name str

The name of the transform.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The transform.

Example

To get a single transformation, you can use the following code:

geoserver.get_transform(transform="test1")
Source code in geoserver/geoserver.py
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
def get_wfs_transform(self, name: str, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Retrieves a single transformation.

    Args:
        name: The name of the transform.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The transform.

    Example:
        To get a single transformation, you can use the following code:

        ```python
        geoserver.get_transform(transform="test1")
        ```
    """
    url = f"{self.service_url}/rest/services/wfs/transforms/{name}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wfs_transform

update_wfs_transform(
    name: str, body: Union[str, Dict[str, Any]]
) -> str

Modifies a single transform.

Parameters:

Name Type Description Default
name str

The name of the transform.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the transform.

required

Returns:

Type Description
str

Success message.

Example

To update a single transformation, you can use the following code:

body = """
<transform>
    <name>test1</name>
    <sourceFormat>text/xml; subtype=gml/2.1.2</sourceFormat>
    <outputFormat>text/html</outputFormat>
    <xslt>test1.xslt</xslt>
</transform>
"""

geoserver.update_transform(transform="test1", body=body)
Source code in geoserver/geoserver.py
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
def update_wfs_transform(self, name: str, body: Union[str, Dict[str, Any]]) -> str:
    """Modifies a single transform.

    Args:
        name: The name of the transform.
        body: The body of the request used to modify the transform.

    Returns:
        Success message.

    Example:
        To update a single transformation, you can use the following code:

        ```python
        body = \"\"\"
        <transform>
            <name>test1</name>
            <sourceFormat>text/xml; subtype=gml/2.1.2</sourceFormat>
            <outputFormat>text/html</outputFormat>
            <xslt>test1.xslt</xslt>
        </transform>
        \"\"\"

        geoserver.update_transform(transform="test1", body=body)
        ```
    """
    url = f"{self.service_url}/rest/services/wfs/transforms/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wfs_transform

delete_wfs_transform(name: str) -> str

Deletes a single transform.

Parameters:

Name Type Description Default
name str

The name of the transform.

required

Returns:

Type Description
str

Success message.

Example

To remove a single transformation, you can use the following code:

geoserver.delete_transform(transform="test1")
Source code in geoserver/geoserver.py
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
def delete_wfs_transform(self, name: str) -> str:
    """Deletes a single transform.

    Args:
        name: The name of the transform.

    Returns:
        Success message.

    Example:
        To remove a single transformation, you can use the following code:

        ```python
        geoserver.delete_transform(transform="test1")
        ```
    """
    url = f"{self.service_url}/rest/services/wfs/transforms/{name}"
    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wms_layers

get_wms_layers(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wms_layers(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["xml"],
) -> str
get_wms_layers(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves the WMS layers available on the server.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
store Optional[str]

Optional. Name of the wms store.

None
list Optional[Literal['available']]

Optional. Set list=available to see all possible layers in the store, not just ones currently published.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMS layers.

Source code in geoserver/geoserver.py
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
def get_wms_layers(
    self,
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Retrieves the WMS layers available on the server.

    Args:
        workspace: The name of the workspace.
        store: Optional. Name of the wms store.
        list: Optional. Set `list=available` to see all possible layers in the store, not just ones currently published.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMS layers.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmslayers.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{store}/wmslayers.{format}"

    params = dict(list=list)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

wms_layer_exists

wms_layer_exists(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
) -> bool

Check if a WMS layer exists.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. The name of the WMS store.

None

Returns:

Type Description
bool

True if the WMS layer exists, False otherwise.

Source code in geoserver/geoserver.py
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
def wms_layer_exists(self, name: str, *, workspace: str, store: Optional[str] = None) -> bool:
    """Check if a WMS layer exists.

    Args:
        name: The name of the layer.
        workspace: The name of the workspace.
        store: Optional. The name of the WMS store.

    Returns:
        True if the WMS layer exists, False otherwise.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmslayers/{name}.xml"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{store}/wmslayers/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_wms_layer

create_wms_layer(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
) -> str

Creates a new WMS layer.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
body Union[str, Dict[str, Any]]

The body of the request used to create the WMS layer.

required
store Optional[str]

Optional. Name of the wms store.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
def create_wms_layer(self, body: Union[str, Dict[str, Any]], *, workspace: str, store: Optional[str] = None) -> str:
    """Creates a new WMS layer.

    Args:
        workspace: The name of the workspace.
        body: The body of the request used to create the WMS layer.
        store: Optional. Name of the wms store.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmslayers"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{store}/wmslayers"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_wms_layer

get_wms_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wms_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_wms_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves a single WMS layer.

Parameters:

Name Type Description Default
name str

The name of the wms layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. Name of the wms store.

None
quiet_on_not_found bool

Optional. When set to "true", will not log an exception when the style is not present. The 404 status code will still be returned.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMS layer.

Source code in geoserver/geoserver.py
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
def get_wms_layer(
    self,
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Retrieves a single WMS layer.

    Args:
        name: The name of the wms layer.
        workspace: The name of the workspace.
        store: Optional. Name of the wms store.
        quiet_on_not_found: Optional. When set to "true", will not log an exception when the style is not present.
            The 404 status code will still be returned.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMS layer.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmslayers/{name}.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{store}/wmslayers/{name}.{format}"

    params = dict(quietOnNotFound=quiet_on_not_found)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

update_wms_layer

update_wms_layer(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
    calculate: Optional[List[str]] = None,
) -> str

Modifies a single WMS layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the WMS layer.

required
workspace str

The name of the workspace.

required
calculate Optional[List[str]]

Specifies whether to recalculate any bounding boxes for a wms layer. Some properties are automatically recalculated when necessary. In particular, the native bounding box is recalculated when the projection or projection policy are changed, and the lat/lon bounding box is recalculated when the native bounding box is recalculated, or when a new native bounding box is explicitly provided in the request. (The native and lat/lon bounding boxes are not automatically recalculated when they are explicitly included in the request.) In addition, the client may explicitly request a fixed set of fields to calculate, by including a comma-separated list of their names in the recalculate parameter. The empty parameter "recalculate=" is useful avoid slow recalculation when operating against large datasets as "recalculate=" avoids calculating any fields, regardless of any changes to projection, projection policy, etc. The nativebbox parameter "recalculate=nativebbox" is used recalculates the native bounding box, while avoiding recalculating the lat/lon bounding box. Recalculate parameters can be used in together - "recalculate=nativebbox,latlonbbox" can be used after a bulk import to recalculates both the native bounding box and the lat/lon bounding box.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
def update_wms_layer(
    self,
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
    calculate: Optional[List[str]] = None,
) -> str:
    """Modifies a single WMS layer.

    Args:
        name: The name of the layer.
        body: The body of the request used to modify the WMS layer.
        workspace: The name of the workspace.
        calculate: Specifies whether to recalculate any bounding boxes for a wms layer.
            Some properties are automatically recalculated when necessary.
            In particular, the native bounding box is recalculated when the projection or projection policy are changed,
            and the lat/lon bounding box is recalculated when the native bounding box is recalculated,
            or when a new native bounding box is explicitly provided in the request.
            (The native and lat/lon bounding boxes are not automatically recalculated when they are explicitly included in the request.)
            In addition, the client may explicitly request a fixed set of fields to calculate,
            by including a comma-separated list of their names in the recalculate parameter.
            The empty parameter "recalculate=" is useful avoid slow recalculation when operating against large datasets
            as "recalculate=" avoids calculating any fields, regardless of any changes to projection, projection policy, etc.
            The nativebbox parameter "recalculate=nativebbox" is used recalculates the native bounding box,
            while avoiding recalculating the lat/lon bounding box. Recalculate parameters can be used in together -
            "recalculate=nativebbox,latlonbbox" can be used after a bulk import to
            recalculates both the native bounding box and the lat/lon bounding box.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmslayers/{name}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{store}/wmslayers/{name}"

    params = dict(calculate=calculate)
    self._request(method="put", url=url, body=body, params=params)
    return UPDATED_MESSAGE

delete_wms_layer

delete_wms_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    recurse: bool = False,
) -> str

Deletes a single WMS layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace str

The name of the workspace.

required
recurse bool

Recursively deletes all layers referenced by the specified wmslayer. A request with recurse=false will fail if any layers reference the wmslayer.

False

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
def delete_wms_layer(self, name: str, *, workspace: str, store: Optional[str] = None, recurse: bool = False) -> str:
    """Deletes a single WMS layer.

    Args:
        name: The name of the layer.
        workspace: The name of the workspace.
        recurse: Recursively deletes all layers referenced by the specified wmslayer.
            A request with `recurse=false` will fail if any layers reference the wmslayer.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmslayers/{name}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{store}/wmslayers/{name}"

    params = dict(recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

get_wms_stores

get_wms_stores(
    *, workspace: str, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_wms_stores(
    *, workspace: str, format: Literal["xml"]
) -> str
get_wms_stores(
    *,
    workspace: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves the WMS stores available on the server.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMS stores.

Source code in geoserver/geoserver.py
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
def get_wms_stores(self, *, workspace: str, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Retrieves the WMS stores available on the server.

    Args:
        workspace: The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMS stores.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

wms_store_exists

wms_store_exists(name: str, *, workspace: str) -> bool

Check if a WMS store exists.

Parameters:

Name Type Description Default
name str

The name of the WMS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
bool

True if the WMS store exists, False otherwise.

Source code in geoserver/geoserver.py
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
def wms_store_exists(self, name: str, *, workspace: str) -> bool:
    """Check if a WMS store exists.

    Args:
        name: The name of the WMS store.
        workspace: The name of the workspace.

    Returns:
        True if the WMS store exists, False otherwise.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{name}.xml"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_wms_store

create_wms_store(
    body: Union[str, Dict[str, Any]], *, workspace: str
) -> str

Creates a new WMS store.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the WMS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Example

To add a new WMS store to the server, you can use the following code:

body = """
<wmsStore>
    <name>remote</name>
    <capabilitiesUrl>http://demo.geoserver.org/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities</capabilitiesUrl>
</wmsStore>
"""

geoserver.create_wms_store(workspace="test", body=body)
Source code in geoserver/geoserver.py
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
def create_wms_store(self, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Creates a new WMS store.

    Args:
        body: The body of the request used to create the WMS store.
        workspace: The name of the workspace.

    Returns:
        Success message.

    Example:
        To add a new WMS store to the server, you can use the following code:

        ```python
        body = \"\"\"
        <wmsStore>
            <name>remote</name>
            <capabilitiesUrl>http://demo.geoserver.org/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities</capabilitiesUrl>
        </wmsStore>
        \"\"\"

        geoserver.create_wms_store(workspace="test", body=body)
        ```
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_wms_store

get_wms_store(
    name: str,
    *,
    workspace: str,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wms_store(
    name: str, *, workspace: str, format: Literal["xml"]
) -> str
get_wms_store(
    name: str,
    *,
    workspace: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves a single WMS store.

Parameters:

Name Type Description Default
name str

The name of the WMS store.

required
workspace str

The name of the workspace.

required
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMS store.

Source code in geoserver/geoserver.py
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
def get_wms_store(
    self, name: str, *, workspace: str, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Retrieves a single WMS store.

    Args:
        name: The name of the WMS store.
        workspace: The name of the workspace.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMS store.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{name}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wms_store

update_wms_store(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
) -> str

Modifies a single WMS store.

Parameters:

Name Type Description Default
name str

The name of the WMS store.

required
workspace str

The name of the workspace.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the WMS store.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
def update_wms_store(self, name: str, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Modifies a single WMS store.

    Args:
        name: The name of the WMS store.
        workspace: The name of the workspace.
        body: The body of the request used to modify the WMS store.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wms_store

delete_wms_store(name: str, *, workspace: str) -> str

Deletes a single WMS store.

Parameters:

Name Type Description Default
name str

The name of the WMS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
def delete_wms_store(self, name: str, *, workspace: str) -> str:
    """Deletes a single WMS store.

    Args:
        name: The name of the WMS store.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmsstores/{name}"
    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_wmts_layers

get_wmts_layers(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wmts_layers(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["xml"],
) -> str
get_wmts_layers(
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves the WMTS layers available on the server.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
store Optional[str]

Name of the wmts store.

None
list Optional[Literal['available']]

Set list=available to see all possible layers in the store, not just ones currently published.

None
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMTS layers.

Source code in geoserver/geoserver.py
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
def get_wmts_layers(
    self,
    *,
    workspace: str,
    store: Optional[str] = None,
    list: Optional[Literal["available"]] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Retrieves the WMTS layers available on the server.

    Args:
        workspace: The name of the workspace.
        store: Name of the wmts store.
        list: Set `list=available` to see all possible layers in the store, not just ones currently published.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMTS layers.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/layers.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{store}/layers.{format}"

    params = dict(list=list)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

wmts_layer_exists

wmts_layer_exists(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
) -> bool

Check if a WMTS layer exists.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Name of the wmts store.

None

Returns:

Type Description
bool

True if the WMTS layer exists, False otherwise.

Source code in geoserver/geoserver.py
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
def wmts_layer_exists(self, name: str, *, workspace: str, store: Optional[str] = None) -> bool:
    """Check if a WMTS layer exists.

    Args:
        name: The name of the layer.
        workspace: The name of the workspace.
        store: Name of the wmts store.

    Returns:
        True if the WMTS layer exists, False otherwise.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}.xml"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{store}/layers/{name}.xml"

    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_wmts_layer

create_wmts_layer(
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
) -> str

Creates a new WMTS layer.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the WMTS layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Name of the wmts store.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
def create_wmts_layer(
    self, body: Union[str, Dict[str, Any]], *, workspace: str, store: Optional[str] = None
) -> str:
    """Creates a new WMTS layer.

    Args:
        body: The body of the request used to create the WMTS layer.
        workspace: The name of the workspace.
        store: Name of the wmts store.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/layers"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{store}/layers"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_wmts_layer

get_wmts_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wmts_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["xml"],
) -> str
get_wmts_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves a single WMTS layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Optional. Name of the wmts store.

None
quiet_on_not_found bool

Optional. When set to "true", will not log an exception when the style is not present. The 404 status code will still be returned.

False
format Literal['json', 'xml']

Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMTS layer.

Source code in geoserver/geoserver.py
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
def get_wmts_layer(
    self,
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    quiet_on_not_found: bool = False,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Retrieves a single WMTS layer.

    Args:
        name: The name of the layer.
        workspace: The name of the workspace.
        store: Optional. Name of the wmts store.
        quiet_on_not_found: Optional. When set to "true", will not log an exception when the style is not present.
            The 404 status code will still be returned.
        format: Optional. The format of the response. It can be either "json" or "xml". Defaults to "json".

    Returns:
        The WMTS layer.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}.{format}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{store}/layers/{name}.{format}"

    params = dict(quietOnNotFound=quiet_on_not_found)
    response = self._request(method="get", url=url, params=params)
    return response.json() if format == "json" else response.text

update_wmts_layer

update_wmts_layer(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
    store: Optional[str] = None,
) -> str

Modifies a single WMTS layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the WMTS layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Name of the wmts store.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
def update_wmts_layer(
    self, name: str, body: Union[str, Dict[str, Any]], *, workspace: str, store: Optional[str] = None
) -> str:
    """Modifies a single WMTS layer.

    Args:
        name: The name of the layer.
        body: The body of the request used to modify the WMTS layer.
        workspace: The name of the workspace.
        store: Name of the wmts store.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{store}/layers/{name}"

    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wmts_layer

delete_wmts_layer(
    name: str,
    *,
    workspace: str,
    store: Optional[str] = None,
    recurse: bool = False,
) -> str

Deletes a single WMTS layer.

Parameters:

Name Type Description Default
name str

The name of the layer.

required
workspace str

The name of the workspace.

required
store Optional[str]

Name of the wmts store.

None
recurse bool

Recursively deletes all layers referenced by the specified wmtslayer. A request with recurse=false will fail if any layers reference the wmtslayer.

False

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
def delete_wmts_layer(
    self, name: str, *, workspace: str, store: Optional[str] = None, recurse: bool = False
) -> str:
    """Deletes a single WMTS layer.

    Args:
        name: The name of the layer.
        workspace: The name of the workspace.
        store: Name of the wmts store.
        recurse: Recursively deletes all layers referenced by the specified wmtslayer.
            A request with `recurse=false` will fail if any layers reference the wmtslayer.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/layers/{name}"
    if store is not None:
        url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{store}/layers/{name}"

    params = dict(recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

get_wmts_stores

get_wmts_stores(
    *, workspace: str, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_wmts_stores(
    *, workspace: str, format: Literal["xml"]
) -> str
get_wmts_stores(
    *,
    workspace: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves the WMTS stores available on the server.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMTS stores.

Source code in geoserver/geoserver.py
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
def get_wmts_stores(self, *, workspace: str, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Retrieves the WMTS stores available on the server.

    Args:
        workspace: The name of the workspace.
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The WMTS stores.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

wmts_store_exists

wmts_store_exists(name: str, *, workspace: str) -> bool

Checks if a WMTS store exists on the server.

Parameters:

Name Type Description Default
name str

The name of the WMTS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
bool

True if the WMTS store exists, False otherwise.

Source code in geoserver/geoserver.py
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
def wmts_store_exists(self, name: str, *, workspace: str) -> bool:
    """Checks if a WMTS store exists on the server.

    Args:
        name: The name of the WMTS store.
        workspace: The name of the workspace.

    Returns:
        True if the WMTS store exists, False otherwise.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{name}.xml"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_wmts_store

create_wmts_store(
    body: Union[str, Dict[str, Any]], *, workspace: str
) -> str

Creates a new WMTS store.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the WMTS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
def create_wmts_store(self, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Creates a new WMTS store.

    Args:
        body: The body of the request used to create the WMTS store.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

get_wmts_store

get_wmts_store(
    name: str,
    *,
    workspace: str,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_wmts_store(
    name: str, *, workspace: str, format: Literal["xml"]
) -> str
get_wmts_store(
    name: str,
    *,
    workspace: str,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Retrieves a single WMTS store.

Parameters:

Name Type Description Default
name str

The name of the WMTS store.

required
workspace str

The name of the workspace.

required
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The WMTS store.

Source code in geoserver/geoserver.py
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
def get_wmts_store(
    self, name: str, *, workspace: str, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Retrieves a single WMTS store.

    Args:
        name: The name of the WMTS store.
        workspace: The name of the workspace.
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The WMTS store.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{name}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_wmts_store

update_wmts_store(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    workspace: str,
) -> str

Modifies a single WMTS store.

Parameters:

Name Type Description Default
name str

The name of the WMTS store.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the WMTS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
def update_wmts_store(self, name: str, body: Union[str, Dict[str, Any]], *, workspace: str) -> str:
    """Modifies a single WMTS store.

    Args:
        name: The name of the WMTS store.
        body: The body of the request used to modify the WMTS store.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_wmts_store

delete_wmts_store(name: str, *, workspace: str) -> str

Deletes a single WMTS store.

Parameters:

Name Type Description Default
name str

The name of the WMTS store.

required
workspace str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
def delete_wmts_store(self, name: str, *, workspace: str) -> str:
    """Deletes a single WMTS store.

    Args:
        name: The name of the WMTS store.
        workspace: The name of the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{workspace}/wmtsstores/{name}"
    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_workspaces

get_workspaces(
    *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_workspaces(*, format: Literal['xml']) -> str
get_workspaces(
    *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays a list of all workspaces on the server.

Parameters:

Name Type Description Default
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The workspaces.

Source code in geoserver/geoserver.py
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
def get_workspaces(self, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays a list of all workspaces on the server.

    Args:
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The workspaces.
    """
    url = f"{self.service_url}/rest/workspaces.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

workspace_exists

workspace_exists(name: str) -> bool

Checks if a workspace exists on the server.

Parameters:

Name Type Description Default
name str

The name of the workspace.

required

Returns:

Type Description
bool

True if the workspace exists, False otherwise.

Source code in geoserver/geoserver.py
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
def workspace_exists(self, name: str) -> bool:
    """Checks if a workspace exists on the server.

    Args:
        name: The name of the workspace.

    Returns:
        True if the workspace exists, False otherwise.
    """
    url = f"{self.service_url}/rest/workspaces/{name}.xml"
    response = self._request(method="head", url=url, ignore=[404])
    return response.status_code == 200

create_workspace

create_workspace(body: Union[str, Dict[str, Any]]) -> str

Creates a new workspace.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
def create_workspace(self, body: Union[str, Dict[str, Any]]) -> str:
    """Creates a new workspace.

    Args:
        body: The body of the request used to create the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces"
    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

create_workspace_from_name

create_workspace_from_name(name: str) -> str

Shortcut to create a new workspace from a name.

Parameters:

Name Type Description Default
name str

The name of the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
def create_workspace_from_name(self, name: str) -> str:
    """Shortcut to create a new workspace from a name.

    Args:
        name: The name of the workspace.

    Returns:
        Success message.
    """
    body = {"workspace": {"name": name}}
    return self.create_workspace(body=body)

get_workspace

get_workspace(
    name: str, *, format: Literal["json"] = "json"
) -> Dict[str, Any]
get_workspace(name: str, *, format: Literal['xml']) -> str
get_workspace(
    name: str, *, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]

Displays a single workspace on the server.

Parameters:

Name Type Description Default
name str

The name of the workspace.

required
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The workspace.

Source code in geoserver/geoserver.py
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
def get_workspace(self, name: str, *, format: Literal["json", "xml"] = "json") -> Union[str, Dict[str, Any]]:
    """Displays a single workspace on the server.

    Args:
        name: The name of the workspace.
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The workspace.
    """
    url = f"{self.service_url}/rest/workspaces/{name}.{format}"
    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

update_workspace

update_workspace(
    name: str, body: Union[str, Dict[str, Any]]
) -> str

Modifies a single workspace.

Parameters:

Name Type Description Default
name str

The name of the workspace.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the workspace.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
def update_workspace(self, name: str, body: Union[str, Dict[str, Any]]) -> str:
    """Modifies a single workspace.

    Args:
        name: The name of the workspace.
        body: The body of the request used to modify the workspace.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{name}"
    self._request(method="put", url=url, body=body)
    return UPDATED_MESSAGE

delete_workspace

delete_workspace(
    name: str, *, recurse: bool = False
) -> str

Deletes a single workspace.

Parameters:

Name Type Description Default
name str

The name of the workspace.

required
recurse bool

Optional. Recursively deletes all resources in the workspace. Defaults to False.

False

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
def delete_workspace(self, name: str, *, recurse: bool = False) -> str:
    """Deletes a single workspace.

    Args:
        name: The name of the workspace.
        recurse: Optional. Recursively deletes all resources in the workspace. Defaults to False.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/workspaces/{name}"
    params = dict(recurse=recurse)
    self._request(method="delete", url=url, params=params)
    return DELETED_MESSAGE

get_users

get_users(
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_users(
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_users(
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Query all users in the default user/group service.

Parameters:

Name Type Description Default
service Optional[str]

Optional. The name of the user/group service.

None
group Optional[str]

Optional. The name of the group.

None
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The users.

Source code in geoserver/geoserver.py
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
def get_users(
    self, *, service: Optional[str] = None, group: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Query all users in the default user/group service.

    Args:
        service: Optional. The name of the user/group service.
        group: Optional. The name of the group.
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The users.
    """
    if service is None and group is None:
        url = f"{self.service_url}/rest/security/usergroup/users.{format}"
    elif service is not None and group is None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/users.{format}"
    elif service is None and group is not None:
        url = f"{self.service_url}/rest/security/usergroup/group/{group}/users.{format}"
    else:
        raise ValueError("Invalid combination of service and group.")

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

create_user

create_user(
    body: Union[str, Dict[str, Any]],
    *,
    service: Optional[str] = None,
) -> str

Add a new user to the default user/group service.

Parameters:

Name Type Description Default
body Union[str, Dict[str, Any]]

The body of the request used to create the user.

required

Returns:

Type Description
str

Success message.

Example

To add a new user to the default user/group service, you can use the following code:

body = {
    "userName": "user",
    "password": "password",
    "enabled": "true",
}
geoserver.create_user(body=body)
Source code in geoserver/geoserver.py
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
def create_user(self, body: Union[str, Dict[str, Any]], *, service: Optional[str] = None) -> str:
    """Add a new user to the default user/group service.

    Args:
        body: The body of the request used to create the user.

    Returns:
        Success message.

    Example:
        To add a new user to the default user/group service, you can use the following code:

        ```python
        body = {
            "userName": "user",
            "password": "password",
            "enabled": "true",
        }
        geoserver.create_user(body=body)
        ```
    """
    url = f"{self.service_url}/rest/security/usergroup/users"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/users"

    self._request(method="post", url=url, body=body)
    return CREATED_MESSAGE

update_user

update_user(
    name: str,
    body: Union[str, Dict[str, Any]],
    *,
    service: Optional[str] = None,
) -> str

Update an existing user in the default user/group service.

Parameters:

Name Type Description Default
name str

The name of the user.

required
body Union[str, Dict[str, Any]]

The body of the request used to modify the user.

required
service Optional[str]

The name of the user/group service.

None

Returns:

Type Description
str

Success message.

Example

To update an existing user in the default user/group service, you can use the following code:

body = """
<user>
    <userName>user</userName>
    <password>password</password>
    <enabled>true</enabled>
</user>
"""

geoserver.update_user("my_user", body=body)
Source code in geoserver/geoserver.py
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
def update_user(self, name: str, body: Union[str, Dict[str, Any]], *, service: Optional[str] = None) -> str:
    """Update an existing user in the default user/group service.

    Args:
        name: The name of the user.
        body: The body of the request used to modify the user.
        service: The name of the user/group service.

    Returns:
        Success message.

    Example:
        To update an existing user in the default user/group service, you can use the following code:

        ```python
        body = \"\"\"
        <user>
            <userName>user</userName>
            <password>password</password>
            <enabled>true</enabled>
        </user>
        \"\"\"

        geoserver.update_user("my_user", body=body)
        ```
    """
    url = f"{self.service_url}/rest/security/usergroup/user/{name}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/user/{name}"

    self._request(method="post", url=url, body=body)
    return UPDATED_MESSAGE

delete_user

delete_user(
    name: str, *, service: Optional[str] = None
) -> str

Remove an existing user from the default user/group service.

Parameters:

Name Type Description Default
name str

The name of the user.

required
service Optional[str]

The name of the user/group service.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
def delete_user(self, name: str, *, service: Optional[str] = None) -> str:
    """Remove an existing user from the default user/group service.

    Args:
        name: The name of the user.
        service: The name of the user/group service.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/usergroup/user/{name}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/user/{name}"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

get_user_groups

get_user_groups(
    *,
    user: str,
    service: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_user_groups(
    *,
    user: str,
    service: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_user_groups(
    *,
    user: str,
    service: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Query all groups in the default user/group service.

Parameters:

Name Type Description Default
user str

The name of the user.

required
service Optional[str]

Optional. The name of the user/group service.

None
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The groups.

Source code in geoserver/geoserver.py
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
def get_user_groups(
    self, *, user: str, service: Optional[str] = None, format: Literal["json", "xml"] = "json"
) -> Union[str, Dict[str, Any]]:
    """Query all groups in the default user/group service.

    Args:
        user: The name of the user.
        service: Optional. The name of the user/group service.
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The groups.
    """
    url = f"{self.service_url}/rest/security/usergroup/user/{user}/groups.{format}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/user/{user}/groups.{format}"

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

associate_user

associate_user(
    user: str, group: str, *, service: Optional[str] = None
) -> str

Associate a user with a group in the default user/group service.

Parameters:

Name Type Description Default
user str

The name of the user.

required
group str

The name of the group.

required
service Optional[str]

The name of the user/group service.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
def associate_user(self, user: str, group: str, *, service: Optional[str] = None) -> str:
    """Associate a user with a group in the default user/group service.

    Args:
        user: The name of the user.
        group: The name of the group.
        service: The name of the user/group service.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/usergroup/user/{user}/group/{group}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/user/{user}/group/{group}"

    self._request(method="post", url=url)
    return OK_MESSAGE

disassociate_user

disassociate_user(
    user: str, group: str, *, service: Optional[str] = None
) -> str

Remove a user from a group in the default user/group service.

Parameters:

Name Type Description Default
user str

The name of the user.

required
group str

The name of the group.

required
service Optional[str]

The name of the user/group service.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
def disassociate_user(self, user: str, group: str, *, service: Optional[str] = None) -> str:
    """Remove a user from a group in the default user/group service.

    Args:
        user: The name of the user.
        group: The name of the group.
        service: The name of the user/group service.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/usergroup/user/{user}/group/{group}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/user/{user}/group/{group}"

    self._request(method="delete", url=url)
    return OK_MESSAGE

create_user_group

create_user_group(
    name: str, *, service: Optional[str] = None
) -> str

Add a new group to the default user/group service.

Parameters:

Name Type Description Default
name str

The name of the group.

required
service Optional[str]

The name of the user/group service.

None

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
def create_user_group(self, name: str, *, service: Optional[str] = None) -> str:
    """Add a new group to the default user/group service.

    Args:
        name: The name of the group.
        service: The name of the user/group service.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/usergroup/group/{name}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/group/{name}"

    self._request(method="post", url=url)
    return OK_MESSAGE

delete_user_group

delete_user_group(
    name: str, *, service: Optional[str] = None
) -> str

Remove a group from the default user/group service.

Parameters:

Name Type Description Default
name str

The name of the group.

required
service Optional[str]

The name of the user/group service.

None

Returns:

Type Description
str

Success message.

Example

To remove a group from the default user/group service, you can use the following code:

geoserver.delete_group(group="group")
Source code in geoserver/geoserver.py
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
def delete_user_group(self, name: str, *, service: Optional[str] = None) -> str:
    """Remove a group from the default user/group service.

    Args:
        name: The name of the group.
        service: The name of the user/group service.

    Returns:
        Success message.

    Example:
        To remove a group from the default user/group service, you can use the following code:

        ```python
        geoserver.delete_group(group="group")
        ```
    """
    url = f"{self.service_url}/rest/security/usergroup/group/{name}"
    if service is not None:
        url = f"{self.service_url}/rest/security/usergroup/service/{service}/group/{name}"

    self._request(method="delete", url=url)
    return OK_MESSAGE

get_roles

get_roles(
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    user: Optional[str] = None,
    format: Literal["json"] = "json",
) -> Dict[str, Any]
get_roles(
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    user: Optional[str] = None,
    format: Literal["xml"],
) -> str
get_roles(
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    user: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]

Query all roles in the default user/group service.

Parameters:

Name Type Description Default
service Optional[str]

Optional. The name of the user/group service.

None
group Optional[str]

Optional. The name of the group.

None
user Optional[str]

Optional. The name of the user.

None
format Literal['json', 'xml']

Optional. The format of the response. Can be either "json" or "xml".

'json'

Returns:

Type Description
Union[str, Dict[str, Any]]

The roles.

Example

To get all roles in the default user/group service, you can use the following code:

geoserver.get_roles()
Source code in geoserver/geoserver.py
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
def get_roles(
    self,
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    user: Optional[str] = None,
    format: Literal["json", "xml"] = "json",
) -> Union[str, Dict[str, Any]]:
    """Query all roles in the default user/group service.

    Args:
        service: Optional. The name of the user/group service.
        group: Optional. The name of the group.
        user: Optional. The name of the user.
        format: Optional. The format of the response. Can be either "json" or "xml".

    Returns:
        The roles.

    Example:
        To get all roles in the default user/group service, you can use the following code:

        ```python
        geoserver.get_roles()
        ```
    """
    if service is None and group is None and user is None:
        url = f"{self.service_url}/rest/security/roles.{format}"
    elif service is not None and group is None and user is None:
        url = f"{self.service_url}/rest/security/roles/service/{service}.{format}"
    elif service is None and group is not None and user is None:
        url = f"{self.service_url}/rest/security/roles/group/{group}.{format}"
    elif service is not None and group is not None and user is None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/group/{group}.{format}"
    elif service is not None and group is None and user is not None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/user/{user}.{format}"
    else:
        raise ValueError("Invalid combination of service, group and user.")

    response = self._request(method="get", url=url)
    return response.json() if format == "json" else response.text

create_role

create_role(name: str) -> str

Add a new role to the default user/group service.

Parameters:

Name Type Description Default
name str

The name of the role.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
def create_role(self, name: str) -> str:
    """Add a new role to the default user/group service.

    Args:
        name: The name of the role.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/roles/role/{name}"

    self._request(method="post", url=url)
    return CREATED_MESSAGE

delete_role

delete_role(name: str) -> str

Remove a role from the default user/group service.

Parameters:

Name Type Description Default
name str

The name of the role.

required

Returns:

Type Description
str

Success message.

Source code in geoserver/geoserver.py
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
def delete_role(self, name: str) -> str:
    """Remove a role from the default user/group service.

    Args:
        name: The name of the role.

    Returns:
        Success message.
    """
    url = f"{self.service_url}/rest/security/roles/role/{name}"

    self._request(method="delete", url=url)
    return DELETED_MESSAGE

associate_role

associate_role(
    role: str,
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    user: Optional[str] = None,
) -> str

Associate a user with a role in the default user/group service.

Parameters:

Name Type Description Default
role str

The name of the role.

required
service Optional[str]

The name of the user/group service.

None
group Optional[str]

The name of the group.

None
user Optional[str]

The name of the user.

None

Returns:

Type Description
str

Success message.

Example

To associate a user with a role in the default user/group service, you can use the following code:

geoserver.associate_role(role="ROLE_ADMIN", user="admin")
Source code in geoserver/geoserver.py
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
def associate_role(
    self, role: str, *, service: Optional[str] = None, group: Optional[str] = None, user: Optional[str] = None
) -> str:
    """Associate a user with a role in the default user/group service.

    Args:
        role: The name of the role.
        service: The name of the user/group service.
        group: The name of the group.
        user: The name of the user.

    Returns:
        Success message.

    Example:
        To associate a user with a role in the default user/group service, you can use the following code:

        ```python
        geoserver.associate_role(role="ROLE_ADMIN", user="admin")
        ```
    """
    if service is not None and group is None and user is None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/role/{role}"
    elif service is None and group is None and user is not None:
        url = f"{self.service_url}/rest/security/roles/role/{role}/user/{user}"
    elif service is None and group is not None and user is None:
        url = f"{self.service_url}/rest/security/roles/role/{role}/group/{group}"
    elif service is not None and group is None and user is not None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/role/{role}/user/{user}"
    elif service is not None and group is not None and user is None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/role/{role}/group/{group}"
    else:
        raise ValueError("Invalid combination of service, group and user.")

    self._request(method="post", url=url)
    return OK_MESSAGE

disassociate_role

disassociate_role(
    role: str,
    *,
    service: Optional[str] = None,
    group: Optional[str] = None,
    user: Optional[str] = None,
) -> str

Disassociate a user with a role in the default user/group service.

Parameters:

Name Type Description Default
role str

The name of the role.

required
service Optional[str]

The name of the user/group service.

None
group Optional[str]

The name of the group.

None
user Optional[str]

The name of the user.

None

Returns:

Type Description
str

Success message.

Example

To disassociate a user from a role in the default user/group service, you can use the following code:

geoserver.disassociate_role(role="ROLE_ADMIN", user="admin")
Source code in geoserver/geoserver.py
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
def disassociate_role(
    self, role: str, *, service: Optional[str] = None, group: Optional[str] = None, user: Optional[str] = None
) -> str:
    """Disassociate a user with a role in the default user/group service.

    Args:
        role: The name of the role.
        service: The name of the user/group service.
        group: The name of the group.
        user: The name of the user.

    Returns:
        Success message.

    Example:
        To disassociate a user from a role in the default user/group service, you can use the following code:

        ```python
        geoserver.disassociate_role(role="ROLE_ADMIN", user="admin")
        ```
    """
    if service is not None and group is None and user is None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/role/{role}"
    elif service is None and group is None and user is not None:
        url = f"{self.service_url}/rest/security/roles/role/{role}/user/{user}"
    elif service is None and group is not None and user is None:
        url = f"{self.service_url}/rest/security/roles/role/{role}/group/{group}"
    elif service is not None and group is None and user is not None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/role/{role}/user/{user}"
    elif service is not None and group is not None and user is None:
        url = f"{self.service_url}/rest/security/roles/service/{service}/role/{role}/group/{group}"
    else:
        raise ValueError("Invalid combination of service, group and user.")

    self._request(method="delete", url=url)
    return OK_MESSAGE