Search for content matching a regular expression pattern within files.
Python SDK
from openviking import OpenViking
client = OpenViking()
# Search for a pattern
results = client.grep(
"viking://resources/" ,
"authentication" ,
case_insensitive = True
)
print ( f "Found { results[ 'count' ] } matches" )
for match in results[ 'matches' ]:
print ( f " { match[ 'uri' ] } : { match[ 'line' ] } " )
print ( f " { match[ 'content' ] } " )
HTTP API
curl -X POST http://localhost:1933/api/v1/search/grep \
-H "Content-Type: application/json" \
-H "X-API-Key: your-key" \
-d '{
"uri": "viking://resources/",
"pattern": "authentication",
"case_insensitive": true
}'
POST /api/v 1 /search/grep
{
"uri" : "viking://resources/" ,
"pattern" : "authentication" ,
"case_insensitive" : true
}
Parameters
Viking URI to search in (file or directory)
Regular expression pattern to search for
Ignore case when matching
Maximum number of files to search
Response
Operation status (ok on success)
Search results Array of match objects Viking URI of the file containing the match
The matching line content
Total number of matches found
Execution time in seconds
{
"status" : "ok" ,
"result" : {
"matches" : [
{
"uri" : "viking://resources/docs/auth.md" ,
"line" : 15 ,
"content" : "User authentication is handled by the AuthService class."
},
{
"uri" : "viking://resources/docs/api.md" ,
"line" : 42 ,
"content" : "All API endpoints require authentication via bearer token."
}
],
"count" : 2
},
"time" : 0.3
}
CLI
openviking grep viking://resources/ "authentication" [--ignore-case]
Pattern Syntax
The pattern parameter accepts standard regular expressions:
authentication - Literal string match
auth.*token - Match “auth” followed by any characters, then “token”
^import - Match lines starting with “import”
TODO|FIXME - Match lines containing either “TODO” or “FIXME”
Searching large directories may take time
Use node_limit to restrict the number of files searched
Directories are searched recursively by default