Skip to main content

k3httpmultipart

Action-CI Documentation Status Package

This module provides some util methods to get multipart headers and body.

k3httpmultipart is a component of pykit3 project: a python3 toolkit set.

Install

pip install k3httpmultipart

Synopsis

import os

import k3fs

import k3httpmultipart

# http request fields
file_path = "/tmp/abc.txt"
k3fs.fwrite(file_path, "123456789")
with open(file_path) as f:
    fields = [
        {
            "name": "aaa",
            "value": "abcde",
        },
        {"name": "bbb", "value": [f, os.path.getsize(file_path), "abc.txt"]},
    ]

    # get http request headers; make_headers() computes Content-Length
    multipart = k3httpmultipart.Multipart()
    res_headers = multipart.make_headers(fields)

    print(res_headers)

    # output:
    # {
    #    'Content-Type': 'multipart/form-data; boundary=75d42525e65d4cf3ba7e1fdbc9ec9787',
    #    'Content-Length': 258,
    # }

    # get http request body reader, from the same object so that the body
    # uses the boundary in the headers
    body_reader = multipart.make_body_reader(fields)
    data = list(body_reader)

    print(b"".join(data).decode("utf-8"))

    # output:
    # --75d42525e65d4cf3ba7e1fdbc9ec9787
    # Content-Disposition: form-data; name=aaa
    #
    # abcde
    # --75d42525e65d4cf3ba7e1fdbc9ec9787
    # Content-Disposition: form-data; name=bbb; filename=abc.txt
    # Content-Type: text/plain
    #
    # 123456789
    # --75d42525e65d4cf3ba7e1fdbc9ec9787--

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3httpmultipart 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3httpmultipart 0.1.9
File Size Uploaded
k3httpmultipart-0.1.9.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3httpmultipart 0.1.9
File Interpreter ABI Platform
k3httpmultipart-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / k3httpmultipart-0.1.9.tar.gz

Download URL k3httpmultipart-0.1.9.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ca6d9b461cb98214c5526443578f15d2e78337630e7045edf039a8dd3605814e
BLAKE2b-256 checksum
How to use checksums
f924ff4e9ada35b46a32d6267f9f8c5b6705875db21926a30d9cb3d00e150c4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3httpmultipart-0.1.9-py3-none-any.whl

Download URL k3httpmultipart-0.1.9-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a45f8c2793a45a7ab54537cad64fa5f182b7a067ef8da804d570ea9ca7eaa49
BLAKE2b-256 checksum
How to use checksums
a9c8ae933fe6e78d53d8841dd71dfd0c41900543576fe6495a4185a43f54e9d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page