Skip to main content

Python client library for SiftDB HTTP API

Project description

SiftDB Python Client

The official Python client library for SiftDB HTTP API.

Installation

pip install siftdb

Quick Start

Basic Usage

from siftdb import SiftDBClient

# Create client instance
client = SiftDBClient(
    base_url="http://localhost:8080",
    default_collection="/path/to/my/collection"
)

# Search for text
results = client.search(
    query="function main",
    path_filter="**/*.py",
    limit=50
)

print(f"Found {results.total_matches} matches in {results.duration_ms}ms")
for hit in results.results:
    print(f"{hit.file_path}:{hit.line_number}: {hit.line_content}")

Context Manager Usage

with SiftDBClient(base_url="http://localhost:8080") as client:
    results = client.search("error handling")
    print(f"Found {len(results.results)} results")

Import Files

# Import files into a collection
import_result = client.import_files(
    source_path="/path/to/source",
    include_patterns=["**/*.py", "**/*.md"],
    exclude_patterns=["**/__pycache__/**", "**/.*"]
)

print(f"Imported {import_result.files_ingested} files")
print(f"Skipped {import_result.files_skipped} files")
if import_result.errors > 0:
    print(f"Encountered {import_result.errors} errors")

List Collections

# List available collections
collections = client.list_collections()
for collection in collections.collections:
    print(f"{collection.name}: {collection.total_files} files, {collection.total_size_bytes} bytes")

Health Check

# Check server health
health = client.health()
print(f"Server status: {health.status}")
print(f"Server version: {health.version}")

API Reference

Client Configuration

SiftDBClient(
    base_url="http://localhost:8080",  # Server URL
    timeout=30,                        # Request timeout in seconds
    default_collection="/path/to/db"   # Default collection path
)

Search Parameters

client.search(
    query="search text",           # Required: search query
    collection="/path/to/db",      # Optional: override default collection
    path_filter="**/*.py",         # Optional: glob pattern for file filtering
    regex=False,                   # Optional: treat query as regex
    limit=1000                     # Optional: max results
)

Import Parameters

client.import_files(
    source_path="/path/to/source",         # Required: source directory
    collection="/path/to/collection",      # Optional: override default collection
    include_patterns=["**/*.py"],          # Optional: files to include
    exclude_patterns=["**/build/**"]       # Optional: files to exclude
)

Error Handling

from siftdb import SiftDBClient, SiftDBException

try:
    client = SiftDBClient()
    results = client.search("my query")
except SiftDBException as e:
    print(f"SiftDB Error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Data Models

SearchResponse

@dataclass
class SearchResponse:
    query: str                    # Original search query
    total_matches: int           # Total number of matches
    results: List[SearchResult]  # Search results
    duration_ms: float          # Search duration

SearchResult

@dataclass
class SearchResult:
    file_path: str      # File path of the match
    line_number: int    # Line number where match occurred
    line_content: str   # Content of the matching line

ImportResponse

@dataclass
class ImportResponse:
    message: str          # Import completion message
    files_ingested: int   # Number of files imported
    files_skipped: int    # Number of files skipped
    errors: int          # Number of errors encountered
    duration_ms: float   # Import duration

Requirements

  • Python 3.8+
  • requests >= 2.25.0

License

MIT

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

siftdb-0.2.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

siftdb-0.2.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file siftdb-0.2.2.tar.gz.

File metadata

  • Download URL: siftdb-0.2.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for siftdb-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a53945ab0dc9c05da93428a75f34c50ff0474ea6b59f14d347b9e09a00771468
MD5 993abf2433f6f3cae74b6e7f81a4d211
BLAKE2b-256 2f3cf9dd55ee617c8a43022678e6cbb684fc67188cad97f39666c0c46d83a8b6

See more details on using hashes here.

File details

Details for the file siftdb-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: siftdb-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for siftdb-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 054d4b71c51571dee4ab891fc310683b68f4d0ada623d45d478cd793f350c3f8
MD5 bcc8f5b9d9b1ac0449d25b299841e8b8
BLAKE2b-256 546014b6b68818bf774b9e9cd011573950d8a218f0d235dc3277d9f4c3361c8b

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