{"id":315,"library":"et-xmlfile","title":"et-xmlfile","description":"A low-memory library for creating large XML files, implementing lxml's xmlfile module for the standard library. Current version: 2.0.0, released on October 25, 2024. Maintained by CharlieX. Requires Python 3.8 or higher. Release cadence: approximately every 3 years.","status":"active","version":"2.0.0","language":"python","source_language":"en","source_url":"https://foss.heptapod.net/openpyxl/et_xmlfile","tags":["XML","low-memory","lxml","xmlfile","Python 3.8+"],"install":[{"cmd":"pip install et-xmlfile","lang":"bash","label":"Install et-xmlfile"}],"dependencies":[],"imports":[{"note":"Ensure correct import path to access the xmlfile context manager.","symbol":"xmlfile","correct":"from et_xmlfile import xmlfile"}],"quickstart":{"code":"from io import BytesIO\nfrom xml.etree.ElementTree import Element\nfrom et_xmlfile import xmlfile\n\nout = BytesIO()\nwith xmlfile(out) as xf:\n    el = Element('root')\n    xf.write(el)\n\nassert out.getvalue() == b'<root />'","lang":"python","description":"A minimal example demonstrating how to use et-xmlfile to create an XML file in memory."},"warnings":[{"fix":"Avoid using the .element() method; instead, create Elements and write them directly.","message":"Using the .element() method on the xmlfile context manager may negatively affect performance. It's recommended to create Elements and write them directly.","severity":"gotcha","affected_versions":"2.0.0"},{"fix":"Avoid running pip as the 'root' user; instead, use a virtual environment for package installation or run pip as a non-root user.","message":"Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead.","severity":"gotcha","affected_versions":"pip:all"},{"fix":"It is recommended to use a virtual environment instead (https://pip.pypa.io/warnings/venv). Alternatively, use the --root-user-action option if you understand the implications and wish to suppress this warning.","message":"Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, potentially rendering your system unusable.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:00:48.694Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install et-xmlfile`","cause":"The `et-xmlfile` library is not installed in the Python environment, or the Python interpreter cannot find it due to an incorrect environment setup or path issue.","error":"ModuleNotFoundError: No module named 'et_xmlfile'"},{"fix":"Ensure you are calling methods like `write()` or `element()` on the `xmlfile` object for streaming, and manipulate `xml.etree.ElementTree.Element` objects for their attributes (like `tag` or `text`) before writing them.","cause":"This error occurs when attempting to access an attribute like 'tag' (which belongs to an `Element` object from `xml.etree.ElementTree`) directly on the `et_xmlfile.xmlfile` object, mistakenly treating the file writer as an XML element.","error":"AttributeError: 'xmlfile' object has no attribute 'tag'"},{"fix":"Ensure that the argument passed to `write()` is an `xml.etree.ElementTree.Element` instance as shown in examples, or a string if writing raw XML data, and matches the expected type of the underlying output stream (e.g., `BytesIO` expects bytes, regular file objects might expect strings).","cause":"The `write()` method of the `xmlfile` object, or an underlying file object, received an argument of an incorrect type (e.g., bytes instead of a string or an `Element` object), or vice-versa depending on the context manager's stream type.","error":"TypeError: write() argument must be str, not bytes"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":3.9,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":3.9,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":3.9,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":3.9,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":4,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":4,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":4.3,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":4.1,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":3.8,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":3.8,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}