Reference
sopsy
SOPSy, a Python wrapper around SOPS.
SOPS binary must be installed and available in your $PATH
.
Modules:
Name | Description |
---|---|
errors |
SOPSy Exceptions. |
sopsy |
SOPSy, a Python wrapper around SOPS. |
utils |
SOPSy utils. |
Classes:
Name | Description |
---|---|
Sops |
SOPS file object. |
SopsyCommandFailedError |
Sopsy could not execute SOPS command successfully. |
SopsyCommandNotFoundError |
Sopsy could not find SOPS command in PATH. |
SopsyConfigNotFoundError |
Sopsy could not find the given configuration file. |
SopsyError |
Sopsy base exception class. |
SopsyInOutType |
SOPS output types. |
SopsyInputSource |
SOPS input source. |
SopsyUnparsableOutpoutTypeError |
Sopsy could not read SOPS output content. |
Sops
Sops(
file: str | Path | bytes,
*,
binary_path: str | Path | None = None,
config: str | Path | None = None,
config_dict: dict[str, Any] | None = None,
extract: str | None = None,
in_place: bool = False,
input_type: str | SopsyInOutType | None = None,
output: str | Path | None = None,
output_type: str | SopsyInOutType | None = None,
input_source: SopsyInputSource = FILE
)
SOPS file object.
Attributes:
Name | Type | Description |
---|---|---|
bin |
Path
|
Path to the SOPS binary. |
file |
str | Path | bytes
|
Path to the SOPS file or content to encrypt/decrypt. |
global_args |
list[str]
|
The list of arguments that will be passed to the |
input_source |
SopsyInputSource
|
Wether input data come from a file or stdin. |
Examples:
>>> from pathlib import Path
>>> from sopsy import Sops
>>> sops = Sops(
>>> binary_path="/app/bin/my_custom_sops",
>>> config=Path(".config/sops.yml"),
>>> file=Path("secrets.json"),
>>> )
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | Path | bytes
|
Path to the SOPS file or content to encrypt/decrypt. |
required |
|
str | Path | None
|
Path to a custom SOPS config file. |
None
|
|
dict[str, Any] | None
|
Allow to pass SOPS config as a python dict. |
None
|
|
str | None
|
Extract a specific key or branch from the input document. |
None
|
|
bool
|
Write output back to the same file instead of stdout. |
False
|
|
str | SopsyInOutType | None
|
If not set, sops will use the file's extension to determine the type. |
None
|
|
str | Path | None
|
Save the output after encryption or decryption to the file specified. |
None
|
|
str | SopsyInOutType | None
|
If not set, sops will use the input file's extension to determine the output format. |
None
|
|
str | Path | None
|
Path to the SOPS binary. If not defined it will search for it in the PATH environment variable. |
None
|
|
SopsyInputSource
|
Wether input data come from a file or stdin. |
FILE
|
Methods:
Name | Description |
---|---|
decrypt |
Decrypt SOPS file. |
encrypt |
Encrypt SOPS file. |
get |
Get a specific key from a SOPS encrypted file. |
rotate |
Rotate encryption keys and re-encrypt values from SOPS file. |
Source code in src/sopsy/sopsy.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
decrypt
Decrypt SOPS file.
Examples:
>>> from sopsy import Sops, SopsyInOutType
>>> sops = Sops("secrets.json", output_type=SopsyInOutType.YAML)
>>> sops.decrypt(to_dict=False)
hello: world
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bool
|
Return the output as a Python dict. |
True
|
Returns:
Type | Description |
---|---|
str | bytes | dict[str, Any] | None
|
The output of the sops command. |
Source code in src/sopsy/sopsy.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
encrypt
Encrypt SOPS file.
Examples:
>>> import json
>>> from pathlib import Path
>>> from sopsy import Sops
>>> secrets = Path("secrets.json")
>>> secrets.write_text(json.dumps({"hello": "world"}))
>>> sops = Sops(secrets, in_place=True)
>>> sops.encrypt()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bool
|
Return the output as a Python dict. |
True
|
Returns:
Type | Description |
---|---|
str | bytes | dict[str, Any] | None
|
The output of the sops command. |
Source code in src/sopsy/sopsy.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
get
Get a specific key from a SOPS encrypted file.
Examples:
>>> from sopsy import Sops
>>> sops = Sops("secrets.json")
>>> sops.get("hello")
b'world'
>>> sops.get("nonexistent", default="DefaultValue")
'DefaultValue'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The key to fetch in the SOPS file content. |
required |
|
Any
|
A default value in case the key does not exist or is empty. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The value of the given key, or the default value. |
Source code in src/sopsy/sopsy.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
rotate
Rotate encryption keys and re-encrypt values from SOPS file.
Examples:
>>> from sopsy import Sops
>>> sops = Sops("secrets.json", in_place=True)
>>> sops.rotate()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bool
|
Return the output as a Python dict. |
True
|
Returns:
Type | Description |
---|---|
str | bytes | dict[str, Any] | None
|
The output of the sops command. |
Source code in src/sopsy/sopsy.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
SopsyCommandFailedError
Bases: SopsyError
Sopsy could not execute SOPS command successfully.
SopsyCommandNotFoundError
Bases: SopsyError
Sopsy could not find SOPS command in PATH.
SopsyConfigNotFoundError
Bases: SopsyError
Sopsy could not find the given configuration file.
SopsyError
Bases: Exception
Sopsy base exception class.
SopsyInOutType
SopsyInputSource
SopsyUnparsableOutpoutTypeError
Bases: SopsyError
Sopsy could not read SOPS output content.