Logging into SciServer Locally#
After installing astropathdb, create an
AstroDB using an available credential source:
from astropathdb import AstroDB
db = AstroDB()
Source selection#
Outside SciServer Compute, authentication selects the first applicable source:
Explicit
usernameandpassword.Explicit
credential_filename.Explicit
usernamewithout a password. A password without a username is invalid.ASTROPATHDB_TOKEN.The existing SciScript session token, including its
--identbehavior.The file configured by
ASTROPATHDB_CREDENTIALS_FILE.ASTROPATHDB_USERNAMEandASTROPATHDB_PASSWORD.scicreds/sciserver_creds.txtin a source checkout.
Explicit arguments never conflict: a higher-ranked argument is used and the rest are ignored. A selected source is authoritative. Invalid or incomplete data does not fall through to another account. A selected username with a missing password can use that exact account’s keyring entry; otherwise authentication fails without prompting. Empty environment values count as absent. No username is combined with a password from another file or environment source. A failed login never falls back to an older token.
The only file searched automatically is scicreds/sciserver_creds.txt at the root of
the package’s source checkout. It is skipped when missing; a malformed or incomplete
file fails at that source. Explicit and environment-configured files must exist and
contain usable credentials. Their relative paths use the current working directory, and
~ expands to the home directory.
Credential file formats#
A .env recognizes these fields; a token can be supplied instead of the pair:
ASTROPATHDB_USERNAME=account
ASTROPATHDB_PASSWORD='password supplied securely'
# Alternatively: ASTROPATHDB_TOKEN=token supplied securely
Dotenv values do not modify the process environment. Variable interpolation is disabled,
so a password containing ${HOME} stays literal. Quoted password whitespace is
preserved. Malformed dotenv input fails, even if some fields could be parsed.
JSON files contain an object with string username, password, or token fields;
null means absent. A nonempty token takes priority within the file:
{"username": "account", "password": "password supplied securely"}
Text files contain the username and password on the first two lines. Both lines are stripped of surrounding whitespace; additional lines are ignored. Direct, JSON, and dotenv passwords retain their nonempty contents exactly. Keep credential files private and out of version control. No authentication option automatically writes a file.
Optional keyring storage#
Install the extra and configure an available operating-system keyring backend:
uv pip install 'astropathdb[keyring]'
Saving is requested on the credential manager rather than on AstroDB. It
writes only after a successful login and replaces that account’s password under
service astropathdb:
from getpass import getpass
from astropathdb.db_io.credentials import CredentialManager
CredentialManager(store="keyring").login("account", getpass())
# A subsequent explicit account selection can use its stored password.
db = AstroDB(username="account")
Without store="keyring" or store="both", no keyring write occurs. Missing or
inaccessible keyrings during automatic lookup leave the password unresolved. Saving
requires a complete resolved username/password pair before login; token-only sources
and Compute sessions cannot be saved. A failed write raises an error stating that the
session is already authenticated, and prevents token export.