https://github.com/sloria/tinynetrc
Read and write .netrc files in Python
https://github.com/sloria/tinynetrc
ftp netrc posix python python-2 python-3
Last synced: about 2 months ago
JSON representation
Read and write .netrc files in Python
- Host: GitHub
- URL: https://github.com/sloria/tinynetrc
- Owner: sloria
- License: mit
- Created: 2017-11-03T01:46:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-17T01:27:22.000Z (almost 3 years ago)
- Last Synced: 2024-04-23T22:19:45.452Z (about 1 year ago)
- Topics: ftp, netrc, posix, python, python-2, python-3
- Language: Python
- Size: 56.6 KB
- Stars: 13
- Watchers: 3
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
*********
tinynetrc
*********.. image:: https://badgen.net/pypi/v/tinynetrc
:alt: pypi badge
:target: https://pypi.org/project/tinynetrc/.. image:: https://badgen.net/travis/sloria/tinynetrc/master
:alt: travis-ci status
:target: https://travis-ci.org/sloria/tinynetrcRead 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
=====.. code-block:: python
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': '[email protected]',
'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``... code-block:: python
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.