---
sidebar:
  label: roboto.http.url_builder
  order: 11
title: roboto.http.url_builder
---
## Module Contents

### UrlBuilder

```python
class roboto.http.url_builder.UrlBuilder(endpoint: str)
```

`from roboto.http.url_builder import UrlBuilder`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/url_builder.py#L11-L54)

Builder of URLs under one endpoint, from a path and an optional query string.

**Parameters**

- **endpoint** (`str`): Base URL every built URL starts with, such as `https://api.roboto.ai`. Trailing slashes are removed.

#### UrlBuilder.build()

```python
def build(path: str, query: Optional[dict[str, Any]] = None)
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/url_builder.py#L23-L37)

Build the URL of `path` under this builder's endpoint, with `query` as its query string.

**Parameters**

- **path** (`str`): Path to append to the endpoint, joined with one `/`. Leading slashes are removed, so `"/v1/datasets"` and `"v1/datasets"` give the same URL.
- **query** (`Optional[dict[str, Any]]`): Query parameters, encoded with `urllib.parse.urlencode`. Each value is converted with `str()`, so a list is sent as one parameter, not one per item. `None` adds no query string; an empty dictionary leaves a bare `?` at the end of the URL.

**Usage**

```python
UrlBuilder("https://api.roboto.ai/").build("/v1/datasets/ds_12345", query={"limit": 10})
# 'https://api.roboto.ai/v1/datasets/ds_12345?limit=10'
```

#### UrlBuilder.url()

```python
@staticmethod
def url(endpoint: str, path: str, query: Optional[dict[str, Any]] = None) -> str
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/http/url_builder.py#L40-L54)

Build the URL of `path` under `endpoint`, with `query` as its query string.

**Parameters**

- **endpoint** (`str`): Base URL to start from, used as given: an endpoint that ends in `/` gives a URL with `//` before the path.
- **path** (`str`): Path to append to the endpoint, with leading slashes removed as in `build`.
- **query** (`Optional[dict[str, Any]]`): Query parameters, encoded as in `build`.

**Returns**

- `str`
