Skip to content

jonaslindmark/txhttpstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

txhttpstream

Twisted Python HTTP client with incremental reading of data

Reasoning

When consuming large http responses that are sent with Transfer-Encoding: chunked it makes sense being able to perform operations on the intermediate results.

Usage

    def handleChunk(result):
        if result is None:
            return
        (chunk, nextChunkDeferred) = result
        return performWork(chunk) \
                .addCallback(lambda ign: nextChunkDeferred.addCallback(handleChunk))

    return txhttpstream.getStreamedPages("http://stream.com/big-result") \
            .addCallback(handleChunk)

Or via iterator and the twisted.task.coiterate pattern

    iterator = txhttpstream.getStreamedPagesIterator("http://stream.com/big-result")    
    work = imap(performWork, iterator)
    ds = [task.coiterate(work) for i in range(10)]
    return defer.gatherResults(ds)

Development

To test run trial tests

About

Twisted Python HTTP client with incremental reading of data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages