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.1.tar.gz (20.9 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.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zoektpy-0.1.1.tar.gz
  • Upload date:
  • Size: 20.9 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.1.tar.gz
Algorithm Hash digest
SHA256 03d0c937813cebb45e2d7f24a45ca340bed9ff5bb5ec65f60f42c204ee4e1f7b
MD5 0557d6c55d9d774c2446b4ba484cebae
BLAKE2b-256 6f3a6cb3c1eb66e6de89737556d8c7a70e8b9c44a278ce86acaa6faf2268a8af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zoektpy-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb9b6b426e072b0ade8c9a5faa44f65719a55e70c5d6f0650fc101341a1cfb9c
MD5 b95004544f6b87049600514d40d521c7
BLAKE2b-256 189ef2b0bb343459a2c5848719178ae8974de19dc741326ca33e00f8214fecfe

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