Skip to main content

For everything that you really should not be hardcoding.

Project description

PyPI - Downloads

This package wants to replace your hardcoded.password, your hardcoded.api_key, actually hardcoded("Everything you really shouldn't be hardcoding").

Try it!

To move a hardcoded value from your code to an external file, use hardcoded.foo as if it was holding your value already.

import hardcoded
print(hardcoded.foo)

How does it work?

On running the code, this will happen:

  • if an environment variable exist with exactly the same name ("foo" in our example), the value of that environment variable is returned
  • if a .env file exists in the current or any parent directory with the variable ("foo" in our example), the value of that .env variable is returned
  • otherwise, hardcoded will find a file holding your data
    • if you initialised hardcoded as hardcoded.File(path='secrets.yml'), secrets.yml is used
    • if you are running code inside a git repository, .hardcoded.yml is used, at the root of the repository (next to .git/)
    • otherwise, ~/.config/hardcoded.yml is used
    • if the file is encrypted:
      • with GPG, then hardcoded interfaces with your GPG installation (possibly using the gpg-agent)
      • if symmetric encryption was used:
        • if a password was cached, it is used to decrypt the data
        • if Apple Keychain is available, a password is requested to decrypt the data
        • if running interactively, you will be asked for a decryption password
    • the (decrypted if needed) YAML data is loaded
    • if "foo" is a key in the YAML, the value of that key is returned
    • if "foo" does not exist in the YAML yet:
      • if not running interactively (stdin is not an open TTY), a KeyError is raised
      • if running interactively, you are asked to input the value
        • if encryption is requested with hardcoded.File(secret=True), the YAML is encrypted:
          • if GPG is available, the YAML is GPG encrypted with a key of your choosing
          • if Apple Keychain is available, a random password is generated and stored in the keychain
          • otherwise, you are asked for a new password
  • the value of foo is returned to your code

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

hardcoded-0.15.3.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

hardcoded-0.15.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file hardcoded-0.15.3.tar.gz.

File metadata

  • Download URL: hardcoded-0.15.3.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Linux/6.14.7-arch2-1

File hashes

Hashes for hardcoded-0.15.3.tar.gz
Algorithm Hash digest
SHA256 65893931b44e4cbaf51fbd3f1409037a6cde2d3396cb5cc7a4f9f7d290bcc424
MD5 b130589f196f697cd1b416d13f639241
BLAKE2b-256 79d7f5209e70289729cb93f4cc1273294aac556ae7329955c1a4f9c95382735e

See more details on using hashes here.

File details

Details for the file hardcoded-0.15.3-py3-none-any.whl.

File metadata

  • Download URL: hardcoded-0.15.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Linux/6.14.7-arch2-1

File hashes

Hashes for hardcoded-0.15.3-py3-none-any.whl
Algorithm Hash digest
SHA256 29170ab123a2bd30c47e82a45426b2c0243fb0f97254376b7cd670a17bcaa8da
MD5 2745c50ba0c3523f9a2be461b1ca1798
BLAKE2b-256 de7cbfef94df7c841cab4a49e2952d2d7c68ba1cad8e2ec3c3b23e10b65b560f

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