Skip to content

feat: AsyncMultipartStreamParser#80

Open
defnull wants to merge 1 commit into
mainfrom
defnull-async-wrapper
Open

feat: AsyncMultipartStreamParser#80
defnull wants to merge 1 commit into
mainfrom
defnull-async-wrapper

Conversation

@defnull

@defnull defnull commented Jun 12, 2026

Copy link
Copy Markdown
Owner

An async-aware wrapper for PushMultipartParser that reads bytes from an awaitable read function on demand and returns AsyncMultipartPart instances that offer convenient async read methods for their payload.

This is still a stream parser, which means that parts are not buffered to disk and can only be read once, and only in the order they appear in the multipart stream. It is still WAY more convenient than using PushMultipartParser directly.

Example usage:

import multipart

async def handle_request(headers: dict[str, str], body_reader: multipart.t_AsyncReader):
    ctype, options = multipart.parse_options_header(headers["content-type"])
    assert ctype == "multipart/form-data"
    parser = multipart.AsyncMultipartStreamParser(
        multipart.PushMultipartParser(boundary=options["boundary"]), body_reader
    )

    async for part in parser:
        print(f"Found: {part.name} ({part.filename or '-'})")
        async for chunk in part.iter_chunks():
            print(f"[{len(chunk)} bytes]")
        print(f"Total size: {part.size}")

Work in Progress

  • Think about a nice(r) API for async applications
  • Implement stuff
  • Get test coverage back to 100%
  • Improve documentation
  • Benchmark this properly

@defnull defnull force-pushed the defnull-async-wrapper branch from 523cb97 to 7ae68f2 Compare June 13, 2026 11:54
An async-aware wrapper for PushMultipartParser that reads bytes from an
awaitable read function on demand and returns AsyncMultipartPart
instances that offer convenient async read methods for their payload.
@defnull defnull force-pushed the defnull-async-wrapper branch from 7ae68f2 to 2316a4c Compare June 13, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant