Skip to main content

Python client library for Zoekt code search

Project description

ZoektPy Logo

ZoektPy

Python client library and CLI for Zoekt code search.

PyPI version License: MIT


Overview

ZoektPy is a modern, fully typed Python client and CLI for interacting with Zoekt, a fast, scalable code search engine. It supports both synchronous and asynchronous usage, rich CLI output, and advanced search features.

  • Search code across repositories using Zoekt's API
  • List repositories and their metadata
  • Filter by language, file, repo, and more
  • Rich CLI output with syntax highlighting (via rich)
  • Fully typed models (via pydantic)
  • Async and sync clients

Installation

pip install zoektpy

Or, for development:

git clone https://github.com/udbhav-44/zoekt-py.git
cd zoekt-py
pip install -e .[dev]

Quickstart

CLI Usage

After installation, the zoekt command is available:

zoekt search "def my_function" --host my.zoekt.server --language python --max-matches 10

List repositories:

zoekt list --host my.zoekt.server

See all options:

zoekt --help

Python API Usage

from zoektpy import ZoektClient

client = ZoektClient(host="my.zoekt.server", port=6070)
result = client.search("def my_function", options={"NumContextLines": 2})

for file in result.Files:
    print(file.FileName, file.Repository)
    for match in file.LineMatches or []:
        print(match.get_decoded_line())

client.close()

Async Usage

import asyncio
from zoektpy import AsyncZoektClient

async def main():
    client = AsyncZoektClient(host="my.zoekt.server")
    result = await client.search("class MyClass")
    for file in result.Files:
        print(file.FileName)
    await client.close()

asyncio.run(main())

Features

  • Synchronous and asynchronous clients
  • Advanced search: by language, file pattern, repo, case sensitivity, symbols, context lines
  • List and filter repositories
  • Rich CLI with colorized output and JSON export
  • Fully typed models and robust error handling

Command-Line Interface (CLI)

The CLI provides convenient access to Zoekt search and repository listing.

Search

zoekt search "<query>" [OPTIONS]

Options:

  • --host (default: localhost)
  • --port (default: 6070)
  • --timeout (default: 10.0)
  • --context, -c: Number of context lines (default: 3)
  • --max-matches, -m: Max matches to display (default: 20)
  • --language, -l: Filter by language
  • --file, -f: Filter by file pattern
  • --repo, -r: Filter by repository
  • --case-sensitive: Enable case sensitivity
  • --json: Output raw JSON
  • --debug: Enable debug output

List Repositories

zoekt list [<query>] [OPTIONS]

Options:

  • --host, --port, --timeout (as above)
  • --json: Output raw JSON

Python API

ZoektClient (sync)

from zoektpy import ZoektClient
client = ZoektClient(host="localhost", port=6070)
result = client.search("foo bar", options={"NumContextLines": 2})
repos = client.list_repositories("repo:myorg/")
client.close()

AsyncZoektClient (async)

from zoektpy import AsyncZoektClient
client = AsyncZoektClient(host="localhost")
result = await client.search("foo bar")
await client.close()

Search Options

You can pass advanced options via the options argument (see SearchOptions in zoektpy.models).

Error Handling

All errors inherit from zoektpy.exceptions.ZoektError.


Development

  1. Clone the repo:
    git clone https://github.com/udbhav-44/zoekt-py.git
    cd zoekt-py
    
  2. Install dependencies:
    pip install -e .[dev]
    
  3. Run tests:
    pytest
    
  4. Lint and format:
    black zoektpy/ tests/
    flake8 zoektpy/
    mypy zoektpy/
    

Contributing

Contributions are welcome! Please open issues or pull requests on GitHub.


License

This project is licensed under the MIT License. See LICENSE for details.


Made with ❤️ by Udbhav Agarwal

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

zoektpy-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

zoektpy-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file zoektpy-0.1.0.tar.gz.

File metadata

  • Download URL: zoektpy-0.1.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for zoektpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 482199ea8a72569967e16743a70594650eb7079f0f842cc14032bcf92c1291c7
MD5 74dacf3d6c7cd2c7d73598a6771d1253
BLAKE2b-256 ba095cb96067981032e47d9211f79be27f8d16e8ef62bfff492497dcaf2254db

See more details on using hashes here.

File details

Details for the file zoektpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zoektpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for zoektpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 344f7f883152ce34bb965d1d5b3d0f01a27b9233fa6dfe6fbd44fd00bbbf0713
MD5 8eadd1a66221f215ab6fa616ebfb5c6c
BLAKE2b-256 58e7df86a3d43f20bb83742d9b3ac06c15734df8d2ace50be07743ee9fdaefa2

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