Skip to content

Module bastionlab

Sub-modules

Classes

Client(channel: grpc.Channel, signing_key: [bastionlab.keys](keys.md).SigningKey)

The Client class provides access to the BastionLab machine learning platform through several attributes.

Initializes the client with a gRPC channel to the BastionLab server.

Class variables

signing_key: Optional[[bastionlab.keys](keys.md).SigningKey]
Signing key used

Instance variables

polars: [bastionlab.polars](polars/index.md).BastionLabPolars
The BastionLabPolars instance used by this client.
tokenizers: [bastionlab.tokenizers](tokenizers/index.md).BastionLabTokenizers
Returns the BastionLabTokenizers instance used by this client.
torch: [bastionlab.torch](torch/index.md).BastionLabTorch
The BastionLabTorch instance used by this client.
Connection(host: str, port: int = 50056, identity: Optional[[bastionlab.keys](keys.md).SigningKey] = None)

This class represents a connection to a remote server. It holds the necessary information to establish and manage the connection, such as the hostname, port, identity (signing key), and token (if applicable).

Class variables

channel: Optional[grpc.Channel]
The underlying gRPC channel.
host: str
The hostname or IP address of the remote server.
identity: Optional[[bastionlab.keys](keys.md).SigningKey]
The signing key to use for authentication. If not provided, the connection will not be authenticated.
port: int
The port to use for the connection. Defaults to 50056.

Instance variables

client: [bastionlab.client](client.md).Client
Returns a Client instance that provides access to the BastionLab machine learning platform.

Methods

close(self)

Closes the connection to the server.

This method is equivalent to calling __exit__ directly, but provides a more intuitive and readable way to close the connection.

GRPCException(err: Union[grpc._channel._InactiveRpcError, grpc._channel._MultiThreadedRendezvous])

A custom exception class for wrapping gRPC errors. This allows for better error handling and display.

Args: err (Union[grpc._channel._InactiveRpcError, grpc._channel._MultiThreadedRendezvous]): The gRPC error that was caught and wrapped by this exception.

Ancestors (in MRO)

  • builtins.Exception
  • builtins.BaseException

Class variables

err: Union[grpc._channel._InactiveRpcError, grpc._channel._MultiThreadedRendezvous] :

Instance variables

code: grpc.StatusCode
The status code of the gRPC error.
Identity()

Static methods

create(name: Optional[str] = 'bastionlab-identity', password: Optional[bytes] = None) ‑> [bastionlab.keys](keys.md).SigningKey

Generate a new signing key with the given name and password.

Args: name: The name to use for the signing key. If not provided, the default name "bastionlab-identity" will be used. password: The password to use to encrypt the signing key. If not provided, the key will not be encrypted.

Returns: The generated signing key.

load(name: str) ‑> [bastionlab.keys](keys.md).SigningKey

Load a signing key with the given name.

Args: name: The name of the signing key to load.

Returns: The signing key with the given name.

PublicKey()

A class for representing a public key. This class provides methods for encrypting and verifying messages, as well as converting the key to and from various formats (e.g. bytes, PEM).

Initialize a PublicKey instance with a given public key type.

Args: key: An EC public key type.

Static methods

from_bytes_content(content: bytes) ‑> [bastionlab.keys](keys.md).PublicKey

Load a PublicKey instance from a DER-encoded byte string.

Args: content: The DER-encoded byte string to load the key from.

Returns: The PublicKey instance loaded from the given byte string.

from_pem(path: str) ‑> [bastionlab.keys](keys.md).PublicKey

Load a PublicKey instance from a PEM-encoded file.

Args: path: The path to the file to load the key from.

Returns: The PublicKey instance loaded from the given file.

from_pem_content(content: bytes) ‑> [bastionlab.keys](keys.md).PublicKey

Load a PublicKey instance from a PEM-encoded byte string.

Args: content: The PEM-encoded byte string to load the key from.

Returns: The PublicKey instance loaded from the given byte string.

Instance variables

hash: bytes

Get the hash of this PublicKey instance.

Returns: The hash of this PublicKey instance.

pem: str

Get the PEM encoding of this PublicKey instance.

Returns: The PEM encoding of this PublicKey instance.

Methods

__eq__(self, o: object) ‑> bool

Compare this PublicKey instance with another object for equality.

Args: o: The object to compare with.

Returns: True if the objects are equal, False otherwise.

as_bytes(self) ‑> bytes

Get the DER encoding of this PublicKey instance.

Returns: The DER encoding of this PublicKey instance.

save_pem(self, path: str) ‑> [bastionlab.keys](keys.md).PublicKey

Save this PublicKey instance to a PEM-encoded file.

Args: path: The path to save the key to.

Returns: This PublicKey instance.

verify(self, signature: bytes, data: bytes) ‑> None

Verify that the given signature is valid for the given data.

Args: signature: A signature to verify. data: The data that the signature should be for.

Raises: ValueError: if the signature is not valid for the given data.

RequestRejected(message='Action cancelled after data access request rejected by data owner')

Exception raised when function tries to use datorama returned after a rejected access request.

Ancestors (in MRO)

  • builtins.Exception
  • builtins.BaseException
SigningKey()

A class for representing a signing key. This class is used for creating digital signatures and verifying them. It contains both the private key (used for signing) and the corresponding public key (used for verification).

Static methods

from_pem(path: str, password: Optional[bytes] = None) ‑> [bastionlab.keys](keys.md).SigningKey

Load a PublicKey instance from a PEM-encoded file.

Args: path: The path to the file to load the key from.

Returns: The PublicKey instance loaded from the given file.

from_pem_content(content: bytes, password: Optional[bytes] = None) ‑> [bastionlab.keys](keys.md).SigningKey

Load a SigningKey instance from a PEM-encoded byte string.

Args: content: The PEM-encoded byte string to load the key from. password: The password to use to decrypt the key, if it is encrypted.

Returns: The SigningKey instance loaded from the given byte string.

generate() ‑> [bastionlab.keys](keys.md).SigningKey

Generate a new SigningKey instance.

Returns: A new SigningKey instance.

keygen(path: str, password: Optional[bytes] = None) ‑> [bastionlab.keys](keys.md).SigningKey

Generate a new signing key and save it to the given file.

Args: path: The path to the file to save the signing key to. password: The password to use to encrypt the signing key. If not provided, the key will not be encrypted.

Returns: The generated signing key.

Instance variables

pubkey: [bastionlab.keys](keys.md).PublicKey

Get the public key associated with this SigningKey instance.

Returns: The public key associated with this SigningKey instance.

Methods

__eq__(self, o: object) ‑> bool
Return self==value.
save_pem(self, path: str, password: Optional[bytes] = None) ‑> [bastionlab.keys](keys.md).SigningKey

Save this PublicKey instance to a PEM-encoded file.

Args: path: The path to save the key to.

Returns: This PublicKey instance.

sign(self, data: bytes) ‑> bytes

Sign the given data with this SigningKey instance's private key.

Args: data: The data to sign.

Returns: The signature for the given data.