---
title: Charmhub | Deploy Data Platform Libs using Charmhub - The Open Operator Collection
description: Deploy the latest version of Data Platform Libs on any cloud.
url: https://charmhub.io/data-platform-libs/libraries/database_provides
---

# Data Platform Libs

[Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

* [Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")
* [Databases](https://charmhub.io/?filter=databases)

Platform:

22.04

stable 81

```
juju deploy data-platform-libs
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/data-platform-libs/libraries/database_provides#drawer)

## charms.data\_platform\_libs.v0.database\_provides

* [*Docstrings*Docstrings](https://charmhub.io/data-platform-libs/libraries/database_provides)
  [*Code*Source code](https://charmhub.io/data-platform-libs/libraries/database_provides/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.data_platform_libs.v0.database_provides
    ```

    [Download database\_provides.py](https://charmhub.io/data-platform-libs/libraries/database_provides/download)
  + *Last updated* 23 Jan 2026
  + *Revision* Library version 0.6

[DEPRECATED] Relation provider side abstraction for database relation.

This library is a uniform interface to a selection of common database
metadata, with added custom events that add convenience to database management,
and methods to set the application related data.

It can be used as the main library in a database charm to handle relations with
application charms or be extended/used as a template when creating a more complete library
(like one that also handles the database and user creation using database specific APIs).

Following an example of using the DatabaseRequestedEvent, in the context of the
database charm code:

```
from charms.data_platform_libs.v0.database_provides import DatabaseProvides

class SampleCharm(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)

        # Charm events defined in the database provides charm library.
        self.provided_database = DatabaseProvides(self, relation_name="database")
        self.framework.observe(self.provided_database.on.database_requested,
            self._on_database_requested)

        # Database generic helper
        self.database = DatabaseHelper()

    def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
        # Handle the event triggered by a new database requested in the relation

        # Retrieve the database name using the charm library.
        db_name = event.database

        # generate a new user credential
        username = self.database.generate_user()
        password = self.database.generate_password()

        # set the credentials for the relation
        self.provided_database.set_credentials(event.relation.id, username, password)

        # set other variables for the relation event.set_tls("False")
```

As shown above, the library provides a custom event (database\_requested) to handle
the situation when an application charm requests a new database to be created.
It's preferred to subscribe to this event instead of relation changed event to avoid
creating a new database when other information other than a database name is
exchanged in the relation databag.

---

Index

* [class DatabaseEvent](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseevent)
* + [def database(
    self)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseevent-database)
* + [def extra\_user\_roles(
    self)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseevent-extra_user_roles)
* [class DatabaseRequestedEvent](https://charmhub.io/data-platform-libs/libraries/database_provides#databaserequestedevent)
* [class DatabaseEvents](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseevents)
* [class DatabaseProvides](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-__init__)
* + [def fetch\_relation\_data(
    self)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-fetch_relation_data)
* + [def relations(
    self)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-relations)
* + [def set\_credentials(
    self,
    relation\_id,
    username,
    password)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_credentials)
* + [def set\_endpoints(
    self,
    relation\_id,
    connection\_strings)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_endpoints)
* + [def set\_read\_only\_endpoints(
    self,
    relation\_id,
    connection\_strings)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_read_only_endpoints)
* + [def set\_replset(
    self,
    relation\_id,
    replset)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_replset)
* + [def set\_tls(
    self,
    relation\_id,
    tls)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_tls)
* + [def set\_tls\_ca(
    self,
    relation\_id,
    tls\_ca)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_tls_ca)
* + [def set\_uris(
    self,
    relation\_id,
    uris)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_uris)
* + [def set\_version(
    self,
    relation\_id,
    version)](https://charmhub.io/data-platform-libs/libraries/database_provides#databaseprovides-set_version)

#### class DatabaseEvent

Description

Base class for database events. None

Methods

DatabaseEvent.
database(

*self*
)

Description

Returns the database that was requested. None

DatabaseEvent.
extra\_user\_roles(

*self*
)

Description

Returns the extra user roles that were requested. None

#### class DatabaseRequestedEvent

Description

Event emitted when a new database is requested for use on this relation. None

#### class DatabaseEvents

Database events.

Description

This class defines the events that the database can emit.

#### class DatabaseProvides

Description

Provides-side of the database relation. None

Methods

DatabaseProvides.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str
)

DatabaseProvides.
fetch\_relation\_data(

*self*
)

Retrieves data from relation.

Returns

a dict of the values stored in the relation data bag
for all relation instances (indexed by the relation id).

Description

This function can be used to retrieve data from a relation
in the charm code when outside an event callback.

DatabaseProvides.
relations(

*self*
)

Description

The list of Relation instances associated with this relation\_name. None

DatabaseProvides.
set\_credentials(

*self*

,
relation\_id: int

,
username: str

,
password: str
)

Set database primary connections.

Arguments

relation\_id

the identifier for a particular relation.

username

user that was created.

password

password of the created user.

Description

This function writes in the application data bag, therefore,
only the leader unit can call it.

DatabaseProvides.
set\_endpoints(

*self*

,
relation\_id: int

,
connection\_strings: str
)

Set database primary connections.

Arguments

relation\_id

the identifier for a particular relation.

connection\_strings

database hosts and ports comma separated list.

Description

This function writes in the application data bag, therefore,
only the leader unit can call it.

DatabaseProvides.
set\_read\_only\_endpoints(

*self*

,
relation\_id: int

,
connection\_strings: str
)

Set database replicas connection strings.

Arguments

relation\_id

the identifier for a particular relation.

connection\_strings

database hosts and ports comma separated list.

Description

This function writes in the application data bag, therefore,
only the leader unit can call it.

DatabaseProvides.
set\_replset(

*self*

,
relation\_id: int

,
replset: str
)

Set replica set name in the application relation databag.

Arguments

relation\_id

the identifier for a particular relation.

replset

replica set name.

Description

MongoDB only.

DatabaseProvides.
set\_tls(

*self*

,
relation\_id: int

,
tls: str
)

Set whether TLS is enabled.

Arguments

relation\_id

the identifier for a particular relation.

tls

whether tls is enabled (True or False).

DatabaseProvides.
set\_tls\_ca(

*self*

,
relation\_id: int

,
tls\_ca: str
)

Set the TLS CA in the application relation databag.

Arguments

relation\_id

the identifier for a particular relation.

tls\_ca

TLS certification authority.

DatabaseProvides.
set\_uris(

*self*

,
relation\_id: int

,
uris: str
)

Set the database connection URIs in the application relation databag.

Arguments

relation\_id

the identifier for a particular relation.

uris

connection URIs.

Description

MongoDB, Redis, OpenSearch and Kafka only.

DatabaseProvides.
set\_version(

*self*

,
relation\_id: int

,
version: str
)

Set the database version in the application relation databag.

Arguments

relation\_id

the identifier for a particular relation.

version

database version.
