Skip to main content

Make http requests based on a CSV input file

Project description

csv2http

ci pypi version Python Versions Maintainability Rating Code Smells Code style: black

CLI tool and library for making a series of JSON or form-encoded HTTP requests based on a CSV file input.

Demo

Quick start

Install

pip install csv2http

Or with pipx (recommended)

pipx install csv2http

Check CLI usage

❯ csv2http --help
usage: csv2http [-h] [-c CONCURRENCY] [--method {POST,PATCH,PUT}] [-a AUTH] [-H [HEADER ...]] [-d] [-n] [-t TIMEOUT] file url

HTTP request for every row of a CSV file - v0.0.3a

positional arguments:
  file                  payload csv file
  url                   URL destination - called with `http` if scheme is absent

options:
  -h, --help            show this help message and exit
  -c CONCURRENCY, --concurrency CONCURRENCY
                        Maximum number of concurrent requests (default: 25)
  --method {POST,PATCH,PUT}
                        HTTP method/verb (default: POST)
  -a AUTH, --auth AUTH  Basic Authentication enter <USERNAME>:<PASSWORD>. If password is blank you will be prompted for input
  -H [HEADER ...], --header [HEADER ...]
                        Header `key:value` pairs
  -d, --form-data       Send payload as form encoded data instead of JSON (default: false)
  -n, --no-save         Do not save results to log file (default: false)
  -t TIMEOUT, --timeout TIMEOUT
                        Connection timeout of the request in seconds (default: 5)

Mockbin Example

Make POST calls to http://mockbin.org from a local csv file.


First setup a new bin, using httpie, curl or the web ui and get a bin id.

❯ http POST mockbin.com/bin/create status:=201 statusText=Created httpVersion=HTTP/1.1 headers:='[]' cookies:='[]' 'content[mimeType]'=application/json --body
"9e95289e-d048-4515-9a61-07f2c74810f5"

Create your my_file.csv and pass it to csv2http. Use the returned bin id from before.

❯ csv2http my_file.csv mockbin.org/bin/9e95289e-d048-4515-9a61-07f2c74810f5 --concurrency 3
 POST http://mockbin.org/bin/mockbin.org/bin/9e95289e-d048-4515-9a61-07f2c74810f5
  status codes - {200: 3}
  status codes - {200: 3}
  status codes - {200: 3}
  status codes - {200: 1}

Check the bin log from. https://mockbin.org/bin/9e95289e-d048-4515-9a61-07f2c74810f5/log

Set Auth and Headers

Header key, value pairs can be set with the -H or -header flag.

Key value pairs should be separated with either a : or =.

csv2http my_file.csv httpbin.org/post -H user-agent:csv2http-cli x-custom-header=foobar

To provide basic auth pass a username and password with -a or --auth.

If the password is omitted you will be prompted to provide it.

--auth my_username:my_password
--auth my_username

Roadmap

  • As Library - Alpha
    • parse csv as dictionary/json - Alpha
    • accept mutator function - Alpha
    • HTTP POST request with json from csv - Alpha
    • limit concurrency - Alpha
    • non-blocking file IO - ???
    • hooks for response results - Beta
    • mkdoc docs - Beta
  • As CLI - Beta
    • argparse - Alpha
    • write results to logfile - Beta
    • progress bar - ???
    • use dedicated CLI library with pretty colors (typer, rich etc.) - Beta
    • Nested fields - V1
  • Complete Docs - V1
    • create_mockbin.csv and example.csv to use in quickstart - Beta
    • examples for using as library
  • GH Actions CI (lint, test, etc.)
  • GH Actions CD (publish to pypi)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv2http-0.0.3a0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv2http-0.0.3a0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file csv2http-0.0.3a0.tar.gz.

File metadata

  • Download URL: csv2http-0.0.3a0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

File hashes

Hashes for csv2http-0.0.3a0.tar.gz
Algorithm Hash digest
SHA256 c6c8c43781d66800402afe606694526c6ce3e8355fdbf49e7d3060c73ffe5b0f
MD5 664bdbef036a54f4e514326a24c2f7e5
BLAKE2b-256 c14f892c2b6b22da6eed3168e1423e6734a9fb01272d6330757eb311d7b639ed

See more details on using hashes here.

File details

Details for the file csv2http-0.0.3a0-py3-none-any.whl.

File metadata

  • Download URL: csv2http-0.0.3a0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/21.5.0

File hashes

Hashes for csv2http-0.0.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ec730755ff1a0b8c3b822418e308345d35c28e54906861a63ce6d8543dc02ee
MD5 954b7d17e0b732abc4d3c3ac2dbaa613
BLAKE2b-256 4a6fccfad1069ae97adfb941c4bc2091e18e59db709820afd16b576a782c51db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page