# How to provide SSL details in the ddf.to\_sql function?

**URL:** https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206
**Category:** Dask DataFrame
**Tags:** sql
**Created:** [January 10, 2022, 5:43pm UTC](https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206 "2022-01-10T17:43:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![10PriyaA](https://yyz1.discourse-cdn.com/flex035/user_avatar/dask.discourse.group/10priyaa/32/146_2.png) [@10PriyaA](https://dask.discourse.group/u/10PriyaA)
#### Post date: [January 10, 2022, 5:43pm UTC](https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206/1 "2022-01-10T17:43:34Z")

</div>

I have just started exploring the dask dataframes. My use-case is fairly simple as it involves reading data from a database table, transforming the data, and then loading the transformed data into another table.  
The database I am connecting to requires SSL. The function, dask.dataframe.read\_sql\_table, provides me with a parameter _engine\_kwargs_ which can be used to provide the necessary details for SSL and hence successfully connects and reads data from the database into a dataframe. However, the function, dask.dataframe.to\_sql, does not have the option to provide this parameter. Due to this reason, I am unable to establish a connection with the database and subsequently unable to write my dask dataframe into the database.

Kindly help me with the alternatives for the same. Thanks in advance.

---

<div class="post-metadata">

### Author: ![scharlottej13](https://yyz1.discourse-cdn.com/flex035/user_avatar/dask.discourse.group/scharlottej13/32/24_2.png) [@scharlottej13](https://dask.discourse.group/u/scharlottej13)
#### Post date: [January 11, 2022, 4:44pm UTC](https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206/2 "2022-01-11T16:44:52Z")

</div>

Hi @10PriyaA and welcome! Thanks for your question, I’m still working on this, but will follow-up soon!

---

<div class="post-metadata">

### Author: ![scharlottej13](https://yyz1.discourse-cdn.com/flex035/user_avatar/dask.discourse.group/scharlottej13/32/24_2.png) [@scharlottej13](https://dask.discourse.group/u/scharlottej13)
#### Post date: [January 11, 2022, 7:37pm UTC](https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206/3 "2022-01-11T19:37:11Z")

</div>

I think I found a solution-- have you tried passing the SSL details via the `uri` argument? Looking at [these SQLAlchemy docs](https://docs.sqlalchemy.org/en/14/dialects/mysql.html#ssl-connections), you can pass in the SSL arguments directly into the URI string, which can then be passed into the [`uri` argument](https://docs.dask.org/en/stable/dataframe-sql.html#why-the-differences) in `dask.dataframe.to_sql`. I wasn’t able to test this with an SSL encrypted database, but here’s a minimal example using the `uri` arg:

```python
import pandas as pd
import dask.dataframe as dd
from sqlalchemy import create_engine

# create some fake data
df = pd.DataFrame([{'i':i, 's':str(i)*2 } for i in range(4)])
ddf = dd.from_pandas(df, npartitions=2)

# create a fake db
uri = 'sqlite:///my-sqlite.db'
create_engine(uri)

# upload, then read from test table
ddf.to_sql("test", uri=uri)
data = dd.read_sql_table(
    "test", uri=uri, npartitions=2, index_col='i'
)

```

One thing to note about this solution, is that your SSL details would have to exist somewhere for your workers to be able to access them.

I think adding `engine_kwargs` to `dask.dataframe.to_sql` would be a nice feature request, and I would encourage you to [open up an issue](https://github.com/dask/dask/contribute)!

---

<div class="post-metadata">

### Author: ![10PriyaA](https://yyz1.discourse-cdn.com/flex035/user_avatar/dask.discourse.group/10priyaa/32/146_2.png) [@10PriyaA](https://dask.discourse.group/u/10PriyaA)
#### Post date: [January 16, 2022, 5:05am UTC](https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206/4 "2022-01-16T05:05:11Z")

</div>

Hi @scharlottej13 , thank you so much for your response. It solved my issue and I am able to establish a connection with the database now!

---

<div class="post-metadata">

### Author: ![scharlottej13](https://yyz1.discourse-cdn.com/flex035/user_avatar/dask.discourse.group/scharlottej13/32/24_2.png) [@scharlottej13](https://dask.discourse.group/u/scharlottej13)
#### Post date: [January 20, 2022, 5:29pm UTC](https://dask.discourse.group/t/how-to-provide-ssl-details-in-the-ddf-to-sql-function/206/5 "2022-01-20T17:29:37Z")

</div>

Glad this fixed your problem @10PriyaA! I also opened up an [issue](https://github.com/dask/dask/issues/8596) for this feature.
