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

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.1.tar.gz (7.3 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.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycachuser-0.0.1.tar.gz
  • Upload date:
  • Size: 7.3 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.1.tar.gz
Algorithm Hash digest
SHA256 85e83e7131d639996b45291fc5850e57e6578a914a2f9a95b921b74cb202d096
MD5 db20ce07d5621b5afd1f0558dc869c15
BLAKE2b-256 dfd3584eaa39f6112ae7d5d0951601302cfc0a7902defbf3c048b0e27638ddc9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycachuser-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 832e074049526b518093ec99137b11a7ff0011855c3e4bfd1781b92600fa28bb
MD5 8dbfd2a1dfb7a3f7919a5ddda4eb1a28
BLAKE2b-256 3846a16a9d63191cf0176f84a4e193fd8df50bf2a316ac822ced75dd17d1fa50

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