ServerConfig#
- class ansys.dpf.core.server_factory.ServerConfig(protocol: str = DEFAULT_COMMUNICATION_PROTOCOL, legacy: bool = DEFAULT_LEGACY, grpc_mode: str = DEFAULT_GRPC_MODE, certificates_dir: pathlib.Path = DEFAULT_CERTIFICATES_DIR)#
Provides an instance of ServerConfig object to manage the server type used.
Warning
Starting with DPF 2026 R1 and PyDPF 0.15.0, the default gRPC server uses mTLS authentication. Please refer to Run DPF Server in Secure mode with mTLS for more information on how to set up the certificates and configure the server and client accordingly. See the
configparameter for more details.The default parameters can be overwritten using the DPF_SERVER_TYPE environment variable. DPF_SERVER_TYPE=INPROCESS, DPF_SERVER_TYPE=GRPC, DPF_SERVER_TYPE=LEGACYGRPC can be used.
- Parameters:
protocol – Communication protocol for DPF server (e.g. InProcess, gRPC)
legacy – If legacy is set to True, the server will be using ansys-grpc-dpf Python module. If not, it will communicate with DPF binaries using ctypes and DPF CLayer calls.
grpc_mode – Grpc mode to use when launching DPF server. Can be one of the members of
ansys.dpf.core.server_factory.GrpcMode. Defaults to mTLS authenticated mode. More information available at Run DPF Server in Secure mode with mTLS.certificates_dir – Path to a directory containing the certificates to use for mTLS authentication. More information available at Run DPF Server in Secure mode with mTLS.
Examples
Use constructor parameters to manually create servers.
>>> from ansys.dpf import core as dpf >>> in_process_config = dpf.ServerConfig( ... protocol=dpf.server_factory.CommunicationProtocols.InProcess, legacy=False) >>> grpc_config = dpf.ServerConfig( ... protocol=dpf.server_factory.CommunicationProtocols.gRPC, legacy=False) >>> legacy_grpc_config = dpf.ServerConfig( ... protocol=dpf.server_factory.CommunicationProtocols.gRPC, legacy=True) >>> in_process_server = dpf.start_local_server(config=in_process_config, as_global=False) >>> grpc_server = dpf.start_local_server(config=grpc_config, as_global=False) >>> legacy_grpc_server = dpf.start_local_server(config=legacy_grpc_config, as_global=False)
Use the environment variable to set the default server configuration.
>>> import os >>> os.environ["DPF_SERVER_TYPE"] = "INPROCESS" >>> dpf.start_local_server()
Overview#
Import detail#
from ansys.dpf.core.server_factory import ServerConfig
Attribute detail#
- ServerConfig.legacy = False#
- ServerConfig.certificates_dir#
Method detail#
- ServerConfig.__str__()#
Return a string representation of the ServerConfig instance.
This method provides a human-readable string summarizing the server configuration, including the protocol and whether it’s using legacy gRPC.
- Returns:
String representation of the ServerConfig instance.
- Return type:
str
- ServerConfig.__eq__(other: ServerConfig)#
Check if two ServerConfig instances are equal.
Compares the current ServerConfig instance with another one to check if they have the same protocol and legacy status.
- Parameters:
other (ServerConfig) – The other ServerConfig instance to compare with.
- Returns:
True if the instances have the same protocol and legacy status, False otherwise.
- Return type:
bool
- ServerConfig.__ne__(other)#
Check if two ServerConfig instances are not equal.
Compares the current ServerConfig instance with another one to check if they have different protocol or legacy status.
- Parameters:
other (ServerConfig) – The other ServerConfig instance to compare with.
- Returns:
True if the instances have different protocol or legacy status, False otherwise.
- Return type:
bool