Replace strings with other strings
Project description
replacements
There is a single class of interest in this project: Replacer
.
It is an object for replacing strings with other strings in json-like objects.
The initializer takes a list of assignments, each of which is a dictionary containing a name
, a type
, and optionally args
and kwargs
.
There are currently 6 implemented types:
identity
: returns the argument passed to it.localfile
: passes theargs
andkwargs
toopen
and then reads the file object. The mode is always 'r'.fsspec
: passes theargs
andkwargs
tofsspec.open
, opens that, and reads. The mode is always 'r'. Requires fsspec to be installed. fsspec has multiple protocols installed, e.g. http(s), (s)ftp and zip. This can also be used for data on S3, if s3fs is installed.awssecret
: takes two arguments:region_name
andsecret_id
. Uses boto to call secretsmanager, and returns the returnedSecretString
.env
: takes two arguments:name
, and optionally adefault
value. If the environment variable doesn't exist and no default value was passed, an AssertionError will be raised.base64uuid4
: the base64 (the url safe "-_" variant) of auuid.uuid4
call. Use this to create a unique id that can be used in multiple derived replacements.
Example:
Replacer([{
"name": "name",
"type": "identity",
"args": ["World"]
}])("Hello, ${name}!")
returns "Hello, World!"
There can be dependencies between the assignments. They are resolved linearly using the list order:
Replacer([
{
"name": "name",
"type": "identity",
"args": ["World"]
},
{
"name": "greeting",
"type": "identity",
"args": ["Hello, ${name}!"]
}
])("${greeting}")
also returns "Hello, World!"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
replacements-1.0.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file replacements-1.0.tar.gz
.
File metadata
- Download URL: replacements-1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cdb83bae88fac09565b93598735abd0cba6a2d91822d8a69f42edfeed2ba569 |
|
MD5 | 1d6d5ea1c4623b169298e6813d7b3fad |
|
BLAKE2b-256 | 0241f29e3a46bb164c5bcb6095d7b625ed42ff14dca28b87e7ed4be21b134a24 |
File details
Details for the file replacements-1.0-py3-none-any.whl
.
File metadata
- Download URL: replacements-1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0d75e563bba22ca7cb375de1b51adb16f27219153595fe51f2bb5c196d6d77 |
|
MD5 | ec60da255070341906690c8c5562a55f |
|
BLAKE2b-256 | ac0a7eb0f72e9d850c4d32cfeb95a805037a58f171f85b2693a8a22d39fc1523 |