# concrete.ml.deployment.fhe\_client\_server.md

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L0)

## module `concrete.ml.deployment.fhe_client_server`

APIs for FHE deployment.

### **Global Variables**

* **CML\_VERSION**

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L28)

### class `FHEModelServer`

Server API to load and run the FHE circuit.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L33)

#### method `__init__`

```python
__init__(path_dir: str)
```

Initialize the FHE API.

**Args:**

* `path_dir` (str): the path to the directory where the circuit is saved

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L45)

#### method `load`

```python
load()
```

Load the circuit.

**Raises:**

* `ValueError`: if mismatch in versions between serialized file and runtime

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L77)

#### method `run`

```python
run(
    serialized_encrypted_quantized_data: bytes,
    serialized_evaluation_keys: bytes
) → bytes
```

Run the model on the server over encrypted data.

**Args:**

* `serialized_encrypted_quantized_data` (bytes): the encrypted, quantized and serialized data
* `serialized_evaluation_keys` (bytes): the serialized evaluation keys

**Returns:**

* `bytes`: the result of the model

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L105)

### class `FHEModelDev`

Dev API to save the model and then load and run the FHE circuit.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L110)

#### method `__init__`

```python
__init__(path_dir: str, model: Any = None)
```

Initialize the FHE API.

**Args:**

* `path_dir` (str): the path to the directory where the circuit is saved
* `model` (Any): the model to use for the FHE API

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L147)

#### method `save`

```python
save(via_mlir: bool = False)
```

Export all needed artifacts for the client and server.

**Arguments:**

* `via_mlir` (bool): serialize with `via_mlir` option from Concrete-Python. For more details on the topic please refer to Concrete-Python's documentation.

**Raises:**

* `Exception`: path\_dir is not empty

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L209)

### class `FHEModelClient`

Client API to encrypt and decrypt FHE data.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L214)

#### method `__init__`

```python
__init__(path_dir: str, key_dir: Optional[str] = None)
```

Initialize the FHE API.

**Args:**

* `path_dir` (str): the path to the directory where the circuit is saved
* `key_dir` (str): the path to the directory where the keys are stored

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L325)

#### method `deserialize_decrypt`

```python
deserialize_decrypt(serialized_encrypted_quantized_result: bytes) → ndarray
```

Deserialize and decrypt the values.

**Args:**

* `serialized_encrypted_quantized_result` (bytes): the serialized, encrypted and quantized result

**Returns:**

* `numpy.ndarray`: the decrypted and deserialized values

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L347)

#### method `deserialize_decrypt_dequantize`

```python
deserialize_decrypt_dequantize(
    serialized_encrypted_quantized_result: bytes
) → ndarray
```

Deserialize, decrypt and de-quantize the values.

**Args:**

* `serialized_encrypted_quantized_result` (bytes): the serialized, encrypted and quantized result

**Returns:**

* `numpy.ndarray`: the decrypted (de-quantized) values

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L290)

#### method `generate_private_and_evaluation_keys`

```python
generate_private_and_evaluation_keys(force=False)
```

Generate the private and evaluation keys.

**Args:**

* `force` (bool): if True, regenerate the keys even if they already exist

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L298)

#### method `get_serialized_evaluation_keys`

```python
get_serialized_evaluation_keys() → bytes
```

Get the serialized evaluation keys.

**Returns:**

* `bytes`: the evaluation keys

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L232)

#### method `load`

```python
load()
```

Load the quantizers along with the FHE specs.

**Raises:**

* `ValueError`: if mismatch in versions between serialized file and runtime

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/fhe_client_server.py#L306)

#### method `quantize_encrypt_serialize`

```python
quantize_encrypt_serialize(x: ndarray) → bytes
```

Quantize, encrypt and serialize the values.

**Args:**

* `x` (numpy.ndarray): the values to quantize, encrypt and serialize

**Returns:**

* `bytes`: the quantized, encrypted and serialized values


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zama.org/concrete-ml/1.1/developer-guide/api/concrete.ml.deployment.fhe_client_server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
