{"id":22328,"library":"safe-netrc","title":"safe-netrc","description":"A drop-in replacement for Python's netrc module that safely parses .netrc files without leaking credentials. Provides the same API but with better error handling and support for permission checks. Current version: 1.0.1, released 2023-08. Monthly releases.","status":"active","version":"1.0.1","language":"python","source_language":"en","source_url":"https://github.com/kfsone/safe-netrc","tags":["netrc","credentials","security","parser"],"install":[{"cmd":"pip install safe-netrc","lang":"bash","label":"Default install"}],"dependencies":[],"imports":[{"note":"The standard library module has no permission checks and may expose passwords. Use safe-netrc's version.","wrong":"import netrc","symbol":"netrc","correct":"from safe_netrc import netrc"}],"quickstart":{"code":"from safe_netrc import netrc\nimport os\n\nhost = 'example.com'\nlogin, _, password = netrc(os.path.expanduser('~/.netrc')).authenticators(host)\nprint(f'Login: {login}')","lang":"python","description":"Parse .netrc file and authenticate to a host. The file must have permissions 600 or less (owner-only read/write)."},"warnings":[{"fix":"Avoid isinstance checks; just use the object directly.","message":"The `netrc` function from safe-netrc returns a different object type than stdlib `netrc.netrc`. It returns a `Netrc` object from safe_netrc, which behaves identically but is not a subclass of stdlib's. Do not use `isinstance` checks.","severity":"breaking","affected_versions":"all"},{"fix":"Run `chmod 600 ~/.netrc` to fix permissions. Or handle the error gracefully.","message":"The file permissions are checked strictly. If your .netrc file has group or world permissions (e.g., 644), safe-netrc raises `NetrcParseError` with \"permissions too open\". stdlib netrc silently accepts such files.","severity":"gotcha","affected_versions":"all"},{"fix":"Always pass a string hostname: `netrc_obj.authenticators('example.com')`.","message":"The `authenticators` method requires the host argument to be a string. Passing bytes or other types will raise TypeError. stdlib netrc also has this requirement, but it's a common mistake.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `chmod 600 ~/.netrc` in the terminal to restrict permissions.","cause":"The .netrc file has permissions that allow other users to read it (e.g., 644). safe-netrc requires permissions to be 600 or less.","error":"safe_netrc.NetrcParseError: permissions too open"},{"fix":"Use `from safe_netrc import netrc` or `import safe_netrc` and access via `safe_netrc.netrc`.","cause":"You are importing the standard library module `netrc` instead of `safe_netrc`. The safe-netrc module is `safe_netrc` and you must import from it.","error":"AttributeError: module 'netrc' has no attribute 'netrc'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}