Introduction to Dynamic CLI in Python
Last Updated :
12 Jul, 2022
In this article, we will see an introduction to Dynamic CLI in Python.
What is Dynamic CLI?
A Modern, user-friendly command-line HTTP client for API testing, It helps a programmer to code more efficiently by increasing one's productivity and by reducing the time and effort required to perform tasks of searching for solutions and making API requests. So without wasting any further time let's get right into it. Also using postman and other software for API testing are good but can be difficult for a beginner, dynamic-cli also provides the functionality of API testing where you can simply make API requests from your terminal.
Installation Using PIP
Use the following command
pip3 install dynamic-cli
Installation Using Virtual Environment
You can use this method to avoid possible issues with dependencies or permissions. This is recommended method
Install virtualenv
pip3 install virtualenv
Create a dynamic-cli virtualenv and install dynamic-cli:
mkvirtualenv dynamic-cli
pip3 install dynamic-cli
If you want to activate the dynamic-cli virtualenv again later, run:
workon dynamic-cli
To deactivate the dynamic-cli virtualenv, run:
deactivate
Searching For Error
Now that dynamic CLI is installed correctly we can move forward and use it. Dynamic CLI offers different command-line arguments for different tasks such as for searching for something we use the command:
dynamic -s
Step 1. After pressing enter you will be asked to enter an error/question to search
Enter Question
Step 2. After that you will be asked to enter tags for a better search this is optional.
Optional Tags
Step 3. Now there will be multiple results to questions you can toggle between each one and get the answer.
Results
Step 4. If you want to open that question in the browser you can press 'enter'.
Opened Browser
Step 5. If you wanna save questions to the playbook for later access you can press 'p'.
Question saved in playbook
Step 6. If you want to quit you can press 'ESC' or 'q'.
Accessing Playbook
You started using dynamic CLI found multiple answers and saved them in the playbook but if you want to retrieve them later to do this you need to access a playbook that is stored in your local storage. To do that you can use the following command.
dynamic -p
This will show all the questions stored in the playbook
PlaybookAPI Testing
Moving on to the next use of dynamic cli you can also send requests to an API and receive responses. There are three HTTP methods you can use as of now which are:
Let's see how to use them one by one, for this tutorial I am going to use reqres.in which is a platform to make sample AJAX requests.
Also once you successfully get a response you can store in your local drive.
GET Method
To perform the GET HTTP method enter the following command to your terminal
dynamic -GET
After you press enter on your terminal it will ask you to enter the URL to make the request after that you will need to enter headers if your request needs headers you can add them then it will get the response and present to you in JSON format after that you will be asked if you want to save results if you press 'Y' then enter the file name you want to store your results in and press enter.
GET MethodPOST Method
To perform the POST HTTP method enter the following command to your terminal
dynamic -POST
In the POST method we send the payload(data) there are two ways using which you can send data in dynamic-cli. First, you will be asked to enter the URL then you can add headers then you will be asked if you want to send payload data or not if you press 'Y' you will be prompted with two choices which are
Sending Payload from terminal
If you choose first then you can send data from the terminal you need to specify data in key:value format just like we specify in the curl request.
After that, you can save the response.
Sending Payload from JSON file
If you choose option two you can send data from the JSON input file. You need to specify the name of the file and you will get the JSON response which you can save.
POST MethodDELETE Method
To perform the DELETE HTTP method enter the following command to your terminal
dynamic -DELETE
Same as other HTTP methods first you will be asked to enter the URL after that headers if the deletion operation is successful you will have the response with HTTP code 204 which represents no content.
DELETE Method
Similar Reads
Introduction to Python for Absolute Beginners Are you a beginner planning to start your career in the competitive world of Programming? Looking resources for Python as an Absolute Beginner? You are at the perfect place. This Python for Beginners page revolves around Step by Step tutorial for learning Python Programming language from very basics
6 min read
Monkey Patching in Python (Dynamic Behavior) In Python, the term monkey patch refers to dynamic (or run-time) modifications of a class or module. In Python, we can actually change the behavior of code at run-time. Python3 1== # monk.py class A: def func(self): print ("func() is being called") We use above module (monk) in below code
1 min read
Introduction to auto-py-to-exe Module In the world of Python development, sharing your application with users who may not have Python installed can be challenging. auto-py-to-exe is a powerful tool that simplifies this process by converting Python scripts into standalone executable files (.exe) for Windows. This makes it easier to distr
4 min read
Defining a Python Function at Runtime One amazing feature of Python is that it lets us create functions while our program is running, instead of just defining them beforehand. This makes our code more flexible and easier to manage. Itâs especially useful for things like metaprogramming, event-driven systems and running code dynamically
3 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
How to Learn Python in 21 Days At present, Python is one of the most versatile and demanded programming languages in the IT world. Statistically, there are around 8-9 Million Python developers across the world and the number is increasing rapidly. Meanwhile, the average salary of an Entry-Level Python Developer in India is around
9 min read
Creating Your Own Python IDE in Python In this article, we are able to embark on an adventure to create your personal Python Integrated Development Environment (IDE) the usage of Python itself, with the assistance of the PyQt library. What is Python IDE?Python IDEs provide a characteristic-rich environment for coding, debugging, and goin
3 min read
Creating Your First Application in Python Python is one of the simplest and most beginner-friendly programming languages available today. It was designed with the goal of making programming easy and accessible, especially for newcomers. In this article, we will guide you through creating your very first Python application from a simple prin
4 min read
Python | Accepting Script Input A lot of people use Python as a replacement for shell scripts, using it to automate common system tasks, such as manipulating files, configuring systems, and so forth. This article aims to describe accepting Script Input via Redirection, Pipes, or Input Files. Problem - To have a script to be able t
2 min read
Cmdparse module in Python The Class which provides a simple framework for writing line-oriented command interpreters is called cmd class. These are often useful for administrative tools, prototypes and test harnesses that will later be wrapped in a more sophisticated interface. The command-line interface can be easily made u
6 min read