{"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,"search_vec":"'-08':41 '1.0.1':38 '2023':40 'api':25 'better':28 'check':35 'credenti':21,45 'current':36 'drop':6 'drop-in':5 'error':29 'file':18 'handl':30 'leak':20 'modul':13 'month':42 'netrc':3,12,17,44 'pars':16 'parser':47 'permiss':34 'provid':22 'python':10 'releas':39,43 'replac':8 'safe':2,15 'safe-netrc':1 'secur':46 'support':32 'version':37 'without':19","created_at":"2026-04-27T17:04:35.516942+00:00","updated_at":"2026-04-27T17:04:35.516942+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/safe-netrc/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}