A generic interactive CLI tool for any OpenAPI documented API.
- Interactive CLI: Browse and execute API endpoints interactively
- Tab Completion: Auto-complete commands and see available options (bash/zsh style)
- Help System: Built-in help for all endpoints and parameters
- JSON Pretty Printing: Responses are formatted for easy reading
- Universal: Works with any valid OpenAPI 3.x specification
- URL & File Support: Load specs from URLs or local files
- Smart Command Naming: Converts
operationIdto snake_case commands
# Install dependencies
pip install requests pyyaml
# Or install from source
git clone <repository>
cd openapi-cli
pip install -e .python -m openapi_cli <url/path/to/openapi.json># From a URL
python -m openapi_cli https://petstore.swagger.io/v2/swagger.json
# From a local file
python -m openapi_cli ./api-spec.yaml
# From a local JSON file
python -m openapi_cli ./openapi.jsonOnce the CLI starts, you can use these commands:
| Command | Description |
|---|---|
help |
Show all available commands |
help <command> |
Show help for a specific command |
<endpoint_command> <args> |
Execute an API endpoint |
q or quit |
Exit the CLI |
Press TAB to:
- Auto-complete command names
- See available commands when typing
- Navigate through possible completions
$ python -m openapi_cli https://petstore.swagger.io/v2/swagger.json
OpenAPI CLI Tool v1.0.0
Loading OpenAPI specification from: https://petstore.swagger.io/v2/swagger.json
Fetching OpenAPI spec from URL...
API: Swagger Petstore v1.0.6
Description: This is a sample server Petstore server.
Loaded 20 API endpoint(s)
Welcome to OpenAPI CLI! Type 'help' to see available commands or 'q' to quit.
> help
Available commands:
help [command] - Show help for a specific command
q, quit - Exit the CLI
API Endpoints:
add_pet - Add a new pet to the store
update_pet - Update an existing pet
find_pets_by_status - Finds Pets by status
find_pets_by_tags - Finds Pets by tags
get_pet_by_id - Find pet by ID
update_pet_with_form - Updates a pet in the store with form data
delete_pet - Deletes a pet
> help get_pet_by_id
get_pet_by_id - Find pet by ID. Returns a single pet.
Method: GET /pet/{petId}
Parameters:
petId (path) (required): ID of pet to return
> get_pet_by_id 1
Making GET request to: https://petstore.swagger.io/v2/pet/1
Status: 200 OK
{
"id": 1,
"category": {
"id": 2,
"name": "Cats"
},
"name": "Cat 1",
"photoUrls": [
"url1",
"url2"
],
"tags": [
{
"id": 1,
"name": "tag1"
}
],
"status": "available"
}
> find_pets_by_status available
Making GET request to: https://petstore.swagger.io/v2/pet/findByStatus?status=available
Status: 200 OK
[
{
"id": 1,
"name": "doggie",
"status": "available"
}
// ... more pets
]
> q
Goodbye!
- Parse OpenAPI Spec: The tool loads and parses the OpenAPI specification from a URL or file
- Generate Commands: Each API endpoint becomes a CLI command following the pattern
<method>_<endpoint> - Interactive Shell: Uses Python's
cmdmodule for the interactive interface - Tab Completion: Leverages the
readlinelibrary for command completion - HTTP Requests: Makes actual HTTP requests using the
requestslibrary - Response Formatting: Pretty-prints JSON responses with proper indentation
Commands are generated from the OpenAPI operationId field, converted to snake_case. If no operationId is present, commands are generated from the HTTP method and path.
Examples:
operationId: "getPetById"โget_pet_by_idoperationId: "findPetsByStatus"โfind_pets_by_statusGET /pet/{petId}โget_pet_petid(if no operationId)
- Python 3.7+
requestslibrary for HTTP requestspyyamllibrary for YAML parsing (optional, for YAML specs)readlinelibrary for tab completion (usually built-in)
- Basic path parameter substitution only
- Query parameters, headers, and request bodies need manual implementation per endpoint
- Authentication is not yet implemented
- Error handling could be more robust
- No support for request body schemas yet
# Clone the repository
git clone <repository>
cd openapi-cli
# Install in development mode
pip install -e .
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black .
# Lint code
flake8 .MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you find any issues or have feature requests, please open an issue on GitHub.
Made with โค๏ธ for the OpenAPI community