Repository navigation
Profiles
A profile remembers the two harmless halves of a canteen login — the username and the canteen number — so neither the command line nor a script has to carry them. The password is not one of those halves: by default it goes to the operating system's own credential store and never touches any file this library writes.
Profiles work from the command line and from Python.
strava-cz profile add skola --username your.username --canteen 3753 --verifyYou are asked for the password on the terminal (it is not echoed), and --verify logs
in once to check it before anything is stored.
strava-cz profile list
strava-cz profile show skola # never prints the password
strava-cz profile default doma # which one --profile defaults to
strava-cz profile remove doma # also clears its keyring entryThe first profile you add becomes the default, and a single profile is the default whether or not it is marked as one.
--secret chooses the store. The default keeps it out of every file.
--secret |
where the password goes | remembered? |
|---|---|---|
keyring (default)
|
the OS credential store | yes |
env |
nowhere; read from $STRAVA_CZ_PASSWORD each run |
no |
prompt |
nowhere; asked for each run | no |
file |
plaintext in the profile file | yes |
keyring uses the keyring package, which talks to
GNOME Keyring or KWallet on Linux, the Keychain on macOS and the Credential Locker on
Windows. Install it with the cli extra:
pip install "strava-cz[cli]"file writes the password in the clear. The file is chmod 0600, which keeps other
users out, but it does not stop anyone who can read your home directory or a backup of
it — and the command says so, loudly, every time you use it. Prefer env on a machine
with no keyring.
$XDG_CONFIG_HOME/strava-cz/profiles.json # ~/.config/... when XDG_CONFIG_HOME is unset
The file is created 0600 inside a 0700 directory and replaced atomically, so an
interrupted write cannot leave half a store behind. A keyring-backed profile looks like
this — note what is missing:
{
"default": "skola",
"profiles": {
"skola": {
"canteen_number": "3753",
"language": "EN",
"secret": "keyring",
"username": "your.username"
}
}
}--profile-store PATH points at a different file, which is useful for testing and for
keeping a service account separate from your own.
In this order, first hit wins:
-
$STRAVA_CZ_PASSWORD_<PROFILE>— the profile name upper-cased, with anything that is not a letter or digit turned into_. Soskolareads$STRAVA_CZ_PASSWORD_SKOLA. -
$STRAVA_CZ_PASSWORD. - Whatever the profile's
secretsays — the keyring, the file, or a prompt.
The environment always wins, including over a keyring profile. That is deliberate: a cron job or a container can drive an existing profile without rewriting it, and one job can drive several accounts by setting the per-profile variable for each.
A server with no desktop session usually has no working keyring. profile add detects
this before storing anything and says what to do instead:
$ strava-cz profile add skola --username u --canteen 3753
error: No usable OS keyring on this machine, so --secret keyring cannot store the
password. Install one with: pip install "strava-cz[cli]" - or use --secret env (reads
$STRAVA_CZ_PASSWORD), --secret prompt (asks every time), or --secret file to accept a
plaintext file.
Nothing is silently written somewhere less safe. A profile created on a laptop with a
keyring also keeps working when the file is copied to such a server, as long as
$STRAVA_CZ_PASSWORD is set there — rule 1 above never needs the keyring.
from strava_cz import StravaCZ
with StravaCZ.from_profile("skola") as strava: # omit the name for the default
strava.menu.fetch()
strava.menu.print()from_profile() accepts the same keyword arguments as StravaCZ, plus:
| argument | meaning |
|---|---|
store |
a ProfileStore to read from, instead of the default location |
password |
skip the lookup entirely and use this |
allow_prompt |
set False where nothing can answer a prompt, so it fails instead of hanging |
Managing profiles directly:
from strava_cz import Profile, ProfileStore, SecretSource
store = ProfileStore() # or ProfileStore("/path/to/profiles.json")
store.save(Profile("skola", "your.username", "3753"), password="...")
store.list() # [Profile(name='skola', ...)]
store.get() # the default profile
store.get("skola")
store.set_default("skola")
store.resolve_password(store.get("skola")) # follows the order above
store.delete("skola") # forgets the keyring entry tooProfile is a frozen dataclass whose repr() never contains the password, so it cannot
leak into a traceback or a log line.
| exception | when |
|---|---|
ProfileNotFoundError |
no such profile, or no default is set |
KeyringUnavailableError |
no usable keyring; the message lists the alternatives |
ProfileError |
anything else — a bad name, a corrupt store, no password to be found |
All three derive from StravaError, so except StravaError still catches everything.
On the command line they all exit with code 6.