akvo.iati.exports.iati_export module

class akvo.iati.exports.iati_export.IatiXML(projects, version='2.03', iati_export=None, excluded_elements=None, utc_now: datetime | None = None)[source]

Bases: object

add_project(project)[source]

Adds a project to the IATI XML.

Parameters:

project – Project object

classmethod create_for_streaming(projects, version='2.03', iati_export=None, excluded_elements=None)[source]

Create an IatiXML instance optimized for streaming without building the full tree in memory.

This factory method creates an instance with the minimum setup needed for streaming, avoiding the memory-intensive tree construction in __init__.

Parameters:
  • projects – QuerySet of Projects (will be optimized with prefetch)

  • version – String of IATI version

  • iati_export – IatiExport Django object

  • excluded_elements – List of fieldnames that should be ignored when exporting

Returns:

IatiXML instance ready for streaming

save_file(org_id, filename)[source]

Export the etree to a file.

Parameters:
  • org – String of Organisation id

  • filename – String of the file name

Returns:

File path

save_file_streaming(org_id, filename)[source]

Export using streaming generation to minimize memory usage.

This method generates XML content in chunks and writes directly to file, preventing memory accumulation during large IATI project exports. Also creates necessary IatiActivityExport records for project tracking.

Parameters:
  • org_id – String of Organisation id

  • filename – String of the file name

Returns:

File path

stream_xml()[source]

Stream XML generation with memory monitoring and cleanup.

This method yields XML content in chunks to prevent memory accumulation during large IATI project exports.

Returns:

Generator yielding XML content chunks as strings

akvo.iati.exports.iati_export.save_iati_xml(dir_path, filename, items)[source]