Skip to main content

senic.cryptoyaml

https://travis-ci.org/getsenic/senic.cryptoyaml.svg?branch=master

cryptoyaml is a python library to manage encrypted YAML files, its motivation was to provide an API for applications to read (and write) potentially sensitive configuration settings (i.e. passwords, personal user information) in encrypted form.

Another motivation is that even in scenarios where the private key to access those settings is persisted alongside the settings themselves, the advantage would be that it becomes trivial to delete those settings securely: you now only need to destroy the key properly and not worry that you leave sensitive bits and bytes on the storage device.

This package is simply a convenience wrapper tailored to that use case. The actual heavy lifting of parsing and writing YAML and encrypting and decrypting it is done by the excellent libraries PyYAML and cryptography respectively. Also, while they support both Python 2.x and 3.x this package only targets Python >= 3.5 (because it’s 2016).

API Usage

Here’s a simple example:

>>> from cryptoyaml import generate_key, CryptoYAML
>>> new_key = generate_key('secret')
>>> config = CryptoYAML('/path/to/settings.yml.aes', keyfile=new_key)

Initially you must generate a key (it uses the Fernet symmetric encryption from the cryptography library) and use it to construct an CryptoYAML instance.

That instance then provides a data attribute which is initally an empty dictionary that you can fill with arbitrary data, provided, the PyYAML library can encode it:

>>> config.data['foo'] = 123

Note, however, that the data is only persisted on the filesystem when you explicitly commit it to disk like so:

>>> config.write()

Once written, the file can be re-read as long as the original secret is still provided:

>>> reread = CryptoYAML('/path/to/settings.yml.aes', keyfile=new_key)
>>> reread.data['foo']
>>> 123

Command Line Usage

Having an encrypted settings file is neat, but sometimes you might want to take a look at it or manipulate it from the command line instead of programmatically.

For this cryptoyaml has three commands for generating a key, creating a new file, reading it and setting individual settings:

# cryptoyaml generate_key mysecret
Created new private key at /Users/senic/Development/senic.cryptoyaml/mysecret
# cryptoyaml create mysettings.yml.aes --keyfile mysecret
created new file at /Users/senic/Development/senic.cryptoyaml/mysettings.yml.aes
# cryptoyaml set mysettings.yml.aes foo bar --keyfile mysecret
foo -> bar
# cryptoyaml cat mysettings.yml.aes --keyfile mysecret
{'foo': 'bar'}

Environment variables

A common practice is to provide the secret key via an environment variable. Simply setting CRYPTOYAML_SECRET will allow you to omit the key for both API usage and for the command line.

Release Information

Changelog

Versions follow CalVer with a strict backwards compatibility policy. The third digit is only for regressions.

0.2.0 (2017-02-27)

  • Re-released as cryptoyaml (instead of senic.cryptoyaml) to make packing simpler and to tone down the branding.

0.1.1 (2017-01-03)

Cosmetic brown bag release…

  • fix README markup.

  • fix namespace declaration (to allow it to co-exist with other senic.* packages).

0.1.0 (2016-12-20)

Initial release.

Metadata

Release files for cryptoyaml3 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cryptoyaml3 0.2.1
File Size Uploaded Provenance Actions
cryptoyaml3-0.2.1.tar.gz 11.9 kB Without provenance Details for cryptoyaml3-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cryptoyaml3 0.2.1
File Interpreter ABI Platform Actions
cryptoyaml3-0.2.1-py3-none-any.whl Python 3 none any Details for cryptoyaml3-0.2.1-py3-none-any.whl

Total release size: 21.2 kB

Release files / cryptoyaml3-0.2.1.tar.gz

Download URL cryptoyaml3-0.2.1.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
959e8c841135840680fad110ea604ee6c6f296a1513b47bf02760fa62dad8f7c
BLAKE2b-256 checksum
How to use checksums
a1fc34e26a7c1b2a8905b496fe70ffc6cf9fee6df36d54a3e8ede922cf96755e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release files / cryptoyaml3-0.2.1-py3-none-any.whl

Download URL cryptoyaml3-0.2.1-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c740af5665e10f23a11d1591eed7dd93a9746c2432a6a52fb1c54b116dd1227e
BLAKE2b-256 checksum
How to use checksums
72a645c8b88cd5a4c678d72270f8d000bc8c47da392733f1a26d559cae0116b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Security for cryptoyaml3 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page