Skip to main content

A Python CLI program to send requests.

Project description

██████╗ ███████╗ ██████╗ ███████╗████████╗
██╔══██╗██╔════╝██╔═══██╗██╔════╝╚══██╔══╝
██████╔╝█████╗  ██║   ██║███████╗   ██║   
██╔══██╗██╔══╝  ██║▄▄ ██║╚════██║   ██║   
██║  ██║███████╗╚██████╔╝███████║   ██║   
╚═╝  ╚═╝╚══════╝ ╚══▀▀═╝ ╚══════╝   ╚═╝   
------------------------------------------
a python cli program to send requests

PyPI License: MIT

Is it just me or is curl a little too complicated? Want something simpler in life? something made for humans? Try reqst -- A Python program that reads a json/yml file for request data and sends the request

Installation

pip install this repo. (Note: Incompatible with Python 2.x)

pip3 install reqst

(or)

pip install reqst

Usage example

To get help with command-line arguments

reqst --help

Using command-line arguments

reqst -f "some/folder/myrequest.yml"

(or)

reqst -f "some/folder/myrequest.json"

Colorize Output

reqst -f "some/folder/myrequest.yml" -c

Disclaimer

sometimes the reqst command doesn't work in windows if the package is installed globally.

to avoid this, install the package in a local virtual env

first, create a env

python3 -m venv env_for_reqst

activate that env

.\env_for_reqst\Scripts\activate

and then pip install. But you will have to activate that env everytime you want to use reqst.

IO Redirection

the response is written to stdout and headers/status are written to stderr so that users can take IO redirection to their advantage. This works on windows, linux and mac.

reqst -f "some/folder/myrequest.yml" > res.json 2> res_headers.txt

both stdout and stderr can be redirected to the same file

reqst -f "some/folder/myrequest.yml" > res.txt 2>&1

Sample request file (myrequest.yml)

GET

url: https://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime=4658
method: get
params:
  offset: 2
  limit: 100
headers:
  accept: text/xml
  accept-language: en
timeout: 5000

File Download (reqst -f "some/folder/myrequest.yml" > book.pdf)

url: http://do1.dr-chuck.com/pythonlearn/EN_us/pythonlearn.pdf
method: get

POST

url: https://jsonplaceholder.typicode.com/todos/
method: POST
headers:
  Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk
  content-type: application/json
data:
  title: walk the dog
  completed: false
timeout: 5000

PUT

url: https://jsonplaceholder.typicode.com/todos/1
method: PUT
headers:
  content-type: application/json
data:
  title: walk the dog
  completed: true
timeout: 5000

DELETE

url: https://jsonplaceholder.typicode.com/todos/1
method: DELETE

Complete request file with all available fields (myrequest.yml)

method: XXX # (REQUIRED) GET, OPTIONS, HEAD, POST, PUT, PATCH, or DELETE
url: XXX # (REQUIRED) must be prefixed with http:// or https://

params: # url query parameters. have as many as you like
  offset: 0
  limit: 10

data: # data for POST
  name: john
  age: 22
  hobbies:
    - running
    - eating
    - sleeping

# you can also type data in json format instead of yaml
data: |
  {
    "name": "john",
    "age": 22,
    "hobbies": ["running", "eating", "sleeping"]
  }

headers: # have as many as you like
  Content-Type: application/json
  Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c


cookies: # have as many as you like
  mycookie: cookievalue
  myothercookie: othercookievalue

timeout: 3.14 # seconds

allow_redirects: true # true or false

proxies: # have as many as you like
  http: http://10.10.1.10:3128
  https: https://10.10.1.11:1080
  ftp: ftp://10.10.1.10:3128

# EITHER verify server's TLS certificate. true or false
verify: true
# OR path to a CA bundle to use
verify: some/folder/cacert.crt

# EITHER path to single ssl client cert file (*.pem)
cert: some/folder/client.pem
# OR (*.cert), (*.key) pair.
cert:
  - some/folder/client.cert
  - some/folder/client.key

Development setup

Clone this repo and install packages listed in requirements.txt

pip3 install -r requirements.txt

Contributing

  1. Fork it (https://github.com/hstoklosa/reqst/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new pull request

Meta

H. Stoklosa - hubert.stoklosa23@gmail.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/hstoklosa/

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

reqst-0.1.2.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

reqst-0.1.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file reqst-0.1.2.tar.gz.

File metadata

  • Download URL: reqst-0.1.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for reqst-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5765a393750a4cec07d7d4844db37b7284a0904848cfae15d4926f28350a6080
MD5 f4640ea0d13dd5a1e6b2c8c0d2503365
BLAKE2b-256 a9b9c37386e83159b6b30555854476701775f1c683df3d1a7fa19eafdaaaac98

See more details on using hashes here.

File details

Details for the file reqst-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: reqst-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for reqst-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a7bc5b2e1e475d6a73a138b9ce684d98f75a26558a423f65936709d18597de7c
MD5 1c1545575a11e371226c78ec9428a50c
BLAKE2b-256 9012f70aba3a036f46ee1d10b6861fa45a21141b6586c43f926d9d434b28cdc2

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