Skip to main content

Reusable libraries for Sourcegraph projects

Project description

src-py-lib

Reusable libraries for Sourcegraph projects

Experimental - This is not a supported Sourcegraph product

This repo was created for Sourcegraph Implementation Engineering deployments, and is not intended, designed, built, or supported for use in any other scenario. Feel free to open issues or PRs, but responses are best effort.

Install

From PyPI:

uv add src-py-lib

From this repository:

uv add git+https://github.com/sourcegraph/src-py-lib.git

Use it for

  • Typed config models loaded from defaults, .env, environment variables, and CLI flags
  • Root logger setup with terminal output, optional JSONL events, timing, and run metadata
  • A shared httpx JSON client with timeouts, retries, Retry-After, and contextual errors
  • Small helpers for TSV output, JSON caches, GraphQL pagination, and batched GraphQL queries
  • Thin clients for Sourcegraph, Linear, Slack, GitHub, Google Sheets, and 1Password

Prefer vendor SDKs when they handle complex auth, token refresh, quota behavior, pagination, retries, or request models better than a thin wrapper

Quick example

Define a project config, parse it once, and configure logging at startup:

from pathlib import Path

import src_py_lib as src


class LinearExportConfig(src.LinearClientConfig):
    output_dir: Path = src.config_field(
        default=Path("."),
        env_var="LINEAR_EXPORT_OUTPUT_DIR",
        cli_flag="--output-dir",
        metavar="PATH",
        help="Directory for generated files.",
    )

config = src.parse_args(LinearExportConfig, description="Export Linear data")

with src.logging(config):
    client = src.linear_client_from_config(config)
    client.validate()
    src.info("Starting export", output_dir=str(config.output_dir))
  • Config precedence is code defaults, .env, shell environment, then CLI overrides
  • parse_args resolves op://... references by default
  • Mark sensitive fields with secret=True so config snapshots redact resolved values
  • src.logging() configures the root logger by default so project code and src_py_lib internals share the same handlers
  • Use event() for timed work, stage() for workflow context, and info() / warning() / error() for structured one-off events

Development

uv sync
uv run ruff format .
uv run ruff check .
uv run pyright
uv run python -m unittest discover -s tests
npx --yes markdownlint-cli2

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

src_py_lib-0.1.1.tar.gz (62.6 kB view details)

Uploaded Source

Built Distribution

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

src_py_lib-0.1.1-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: src_py_lib-0.1.1.tar.gz
  • Upload date:
  • Size: 62.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for src_py_lib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b73dece6b9e1d24992df7a5272c2ad2a3f9b491bcf002891d3b2632ce4d39aa7
MD5 4113fd0f66d40a87ea4edd903c8ef38b
BLAKE2b-256 af665f31e15424d5f4e1f0074e4e5ce30a3ea879693a71dfd9e016552b9d64fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for src_py_lib-0.1.1.tar.gz:

Publisher: release.yml on sourcegraph/src-py-lib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: src_py_lib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for src_py_lib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d40d0cac7f3fadc7793aae96a98f6639d6a6f5a16fdd7456d99a50f30ea46301
MD5 8812bde5a37773560c2d1309cd0e6584
BLAKE2b-256 8f64a627e17fcf0c9e307d109453f3890d306ffc36c03a5ca21bc0759aa790ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for src_py_lib-0.1.1-py3-none-any.whl:

Publisher: release.yml on sourcegraph/src-py-lib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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