Password management

Tool
R
Python
Author

Tony D

Published

March 25, 2025

Password management in R and Python

in R

Option 1 using source

create pass.r and keep it yourself

Code
pass.r
pass1='123'

source the pass.r in the main code

Code
source('pass.r')
pass1
[1] "123"

Option 2 Use Environment variables

open /home/.Renviron

Code
usethis::edit_r_environ()

save following password in .Renviron

Code
fake_userid = "username"
fake_pwd = "password"   

get it back

Code
Sys.getenv("fake_userid")
[1] "username"
Code
Sys.getenv("fake_pwd")
[1] "password"

Option 3 using keyringr package

Code
pak::pak("keyring")
Code
library(keyring)
Code
# Interactively save a secret. This avoids typing the value of the secret
# into the console as this could be recorded in your `.Rhistory`
key_set("account_fake_001")
Code
# Later retrieve that secret
key_get("account_fake_001")

in Python

Option 1 using import

create pass_file.py and keep it yourself

Code
pass_file.py
pass1='123'

call pass_file.py with import

Code
from pass_file import *
#from pass_file import acct
pass_w
'123'
Code
acct_w
'222'