Skip to main content

Grabs and stores credentials in a human-readable yaml file, with passwords saved using the keyring module

Project description

Pycachu

An interactive cache that saves user-submitted credentials and tokens in a yaml file, and passwords in the OS keychain using the keyring module

Install

pip install pycachuser

Getting Started

Once you have imported the module:

import pycachu

You can create a cache. This should always be the first step.

cache = pycachu.Cache("file_name")

This will create a yaml file with the specified name. The file will be created at your current directory location by default, but you can specify a path also:

cache = pycachu.Cache("file_name", path="~/")

NOTE: The trialing / is not added for you,make sure to include it on the path.

Getting a token

When you wish to grab a token, just use the following:

token = cache.get_token("key")

The token will be requested by the user at runtime then saved to the cache yaml file. On running a second time, the token will be grabbed directly from the cache with no user input.

This creates a Token object. You can grab the token with .token

print(token.token)

You can specify your own terminal output for the user, and hide the user input:

token = pycachu.Token(cache, "key", user_prompt="Submit the token: ", hide_input=True)

All kwargs to the Token initiator are carried in Cache.get_token(). This is just a demonstration of the other (more convoluted) method for creating a Token.

Getting a credential

When you wish to grab a credential, just use the following:

credential = cache.get_credential("key")

The user will then be asked for the username and password, if already not saved in the cache. The password will be stored in the OS keychain using Keyring.

This creates a Credential object. You can grab the credentials with .username and .password.

print(credential.username, credential.password)

You can specify your own terminal output for the name and password, and hide the username input (the password input is hidden by default):

credential = pycachu.Credential(
    cache,
    "key",
    username_prompt="Submit the username: ",
    password_prompt="And now the password: ",
    hide_username=True,
    hide_password=False,
)

All kwargs to the Credential initiator are carried in Cache.get_credential(). This is just a demonstration of the other (more convoluted) method for creating a Credential.

Oh no! My token/credential didn't work

Raise a cache error to remove the cache object from the cache

token1.error()
raise pycachu.CacheTokenError(token2)

credential1.error()
raise pycachu.CacheCredentialError(credential2)

This will raise an exception and also remove the token/credential from the cache to be re-entered on next runtime.

If you don't want to raise an Exception, both object have a remove() function:

token.remove()
credential.remove()

Validators

Validators are also imported, these are used to match the input to a set regular expression. By default all inputs use the pycachu.validators.NotEmpty() but you can specify any of the other validators, or create your own Validator class.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycachuser-0.0.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycachuser-0.0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pycachuser-0.0.2.tar.gz.

File metadata

  • Download URL: pycachuser-0.0.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pycachuser-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5a82342af5636c51be43f20e1151b362604b73c9335951b27f47dfdb0b6e3071
MD5 d3b619576098376ed10ad96836144cde
BLAKE2b-256 b0538f96adab578e9bc56930e0e93f5212944d0d952b1e4df50189720cd3a1a4

See more details on using hashes here.

File details

Details for the file pycachuser-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pycachuser-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pycachuser-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f5711805105329a8328aebe3de98e15a24da7d6f6d94274a3777144180700fc
MD5 df1ed6053b2f38b427ccb874f15feb3f
BLAKE2b-256 8c55f1decf7a1120be3120a471fbf81fd3c553cca3ae7bed3106cdb658670b0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page