Read and write .netrc files.
Project description
Read and write .netrc files in Python.
tinynetrc uses the netrc module from the standard library under the hood and adds a few improvements:
Adds write functionality.
Fixes a std lib bug with formatting a .netrc file.*
Parses .netrc into dictionary values rather than tuples.
*This bug is fixed in newer versions of Python.
Get it now
pip install tinynetrc
tinynetrc supports Python >= 2.7 or >= 3.5.
Usage
from tinynetrc import Netrc
netrc = Netrc() # parse ~/.netrc
# Get credentials
netrc['api.heroku.com']['login']
netrc['api.heroku.com']['password']
# Modify an existing entry
netrc['api.heroku.com']['password'] = 'newpassword'
netrc.save() # writes to ~/.netrc
# Add a new entry
netrc['surge.surge.sh'] = {
'login': 'sloria1@gmail.com',
'password': 'secret'
}
netrc.save()
# Removing an new entry
del netrc['surge.surge.sh']
netrc.save()
You can also use Netrc as a context manager, which will automatically save ~/.netrc.
from tinynetrc import Netrc
with Netrc() as netrc:
netrc['api.heroku.com']['password'] = 'newpassword'
assert netrc.is_dirty is True
# saved!
License
MIT licensed. See the bundled LICENSE file for more details.
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
tinynetrc-1.3.1.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for tinynetrc-1.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c7820e5f49c9434d2c4cd74de8a06edbbd45e63a8a2980a90b8a43db8facf7 |
|
MD5 | 28d05be7ca8510cc65ae358f64bf33fc |
|
BLAKE2b-256 | eb0b633691d7cea5129afa622869485d1985b038df1d3597a35848731d106762 |