{"id":24858,"library":"z3c-rml","title":"z3c.rml - Alternative implementation of RML","description":"An alternative implementation of Report Markup Language (RML) for generating PDFs. Provides a Pythonic API to produce RML XML that can be rendered by ReportLab. Current version 5.0.1, requires Python >=3.9. Maintained by the Zope Foundation with a slow release cadence.","status":"active","version":"5.0.1","language":"python","source_language":"en","source_url":"https://github.com/zopefoundation/z3c.rml","tags":["zope","rml","pdf","reportlab","report-markup-language","z3c"],"install":[{"cmd":"pip install z3c-rml","lang":"bash","label":"Default install"}],"dependencies":[{"reason":"Required for PDF generation from RML","package":"reportlab","optional":false}],"imports":[{"note":"RML2PDF is obtained via the module, not directly imported; use the module-level functions.","wrong":"from z3c.rml.rml2pdf import RML2PDF","symbol":"RML2PDF","correct":"from z3c.rml import rml2pdf"},{"note":"Access story elements via attribute of the module, not submodule import.","wrong":"import z3c.rml.story","symbol":"story","correct":"from z3c.rml import story"}],"quickstart":{"code":"from z3c.rml import rml2pdf, story\nfrom io import BytesIO\n\n# Create a simple RML document (this is a Pythonic representation, not raw XML)\ndoc = story.DocTemplate(\n    pagesize=(595.27, 841.89),  # A4\n    title=\"Hello World\"\n)\nstory = doc.story\nstory.append(story.Paragraph(\"Hello, World!\", style=story.ParagraphStyle(name='Normal')))\n\n# Generate PDF\nbuf = BytesIO()\nrml2pdf.go(doc, buf)\nbuf.seek(0)\nprint(\"PDF generated, size:\", len(buf.read()))","lang":"python","description":"Minimal example: create a document, add a paragraph, and render to PDF."},"warnings":[{"fix":"Use `z3c.rml.story` classes (DocTemplate, Paragraph, etc.) instead of manually constructing XML.","message":"z3c.rml uses a Pythonic object model, not raw RML XML. Do not try to pass raw RML strings; use the story objects.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `from z3c.rml import rml2pdf; rml2pdf.go(doc, output)`.","message":"The old `z3c.rml.rml2pdf` module had different function signatures. In version 5.0, the preferred method is `rml2pdf.go(doc, output)`. The old direct class instantiation may still work but is not recommended.","severity":"deprecated","affected_versions":">=5.0"},{"fix":"Ensure output is a writable bytes buffer or a string path to a file.","message":"The library expects a `BytesIO` or a file path for output. Passing a string path works, but avoid passing a file-like object that is not seekable.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `from z3c.rml import story` instead of `import z3c.rml.story`.","cause":"Incorrect import. The library is structured so that `z3c.rml` is a namespace package; you must import submodules explicitly.","error":"AttributeError: module 'z3c.rml' has no attribute 'story'"},{"fix":"Replace `from z3c.rml import RML2PDF` with `from z3c.rml import rml2pdf`.","cause":"Trying to import the old class directly from the package root. In modern versions, use `from z3c.rml import rml2pdf`.","error":"ImportError: cannot import name 'RML2PDF' from 'z3c.rml'"},{"fix":"Correct usage: `rml2pdf.go(doc, output)` where doc is a story.DocTemplate and output is a file path or BytesIO.","cause":"Calling `rml2pdf.go()` without arguments or with incorrect arguments. The function expects a doc and an output.","error":"TypeError: go() takes at least 2 positional arguments (0 given)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}