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.
Semantic Versioning
- Release versions are
major.minor.patch - Because this project is still major version 0:
- Minor version updates are breaking changes
- Patch version updates are not breaking changes
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
httpxJSON 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_argsresolvesop://...references by default- Mark sensitive fields with
secret=Trueso config snapshots redact resolved values src.logging()configures the root logger by default so project code andsrc_py_libinternals share the same handlers- Use
event()for timed work,stage()for workflow context, andinfo()/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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file src_py_lib-0.1.4.tar.gz.
File metadata
- Download URL: src_py_lib-0.1.4.tar.gz
- Upload date:
- Size: 70.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fc781cbc709765dc00f154dc0632c63d6aca90f4b591b0e11f6e176f5c390ae
|
|
| MD5 |
aa9607f644aa2a4e09d1e42772f41f7b
|
|
| BLAKE2b-256 |
42209871c6360e633306e43e473b3817731c88b866194758c223ee9a8c6c3fb9
|
Provenance
The following attestation bundles were made for src_py_lib-0.1.4.tar.gz:
Publisher:
release.yml on sourcegraph/src-py-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
src_py_lib-0.1.4.tar.gz -
Subject digest:
8fc781cbc709765dc00f154dc0632c63d6aca90f4b591b0e11f6e176f5c390ae - Sigstore transparency entry: 1667516998
- Sigstore integration time:
-
Permalink:
sourcegraph/src-py-lib@12c4408dc4e7363c3d4214c37f815b993c97a5e9 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/sourcegraph
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@12c4408dc4e7363c3d4214c37f815b993c97a5e9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file src_py_lib-0.1.4-py3-none-any.whl.
File metadata
- Download URL: src_py_lib-0.1.4-py3-none-any.whl
- Upload date:
- Size: 44.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6325dfd85129dcc85f0474425ba2654698e77a539696f82e3595a3729e2e005
|
|
| MD5 |
1dfdefbc70d3eccbf73f2e9ee70df09a
|
|
| BLAKE2b-256 |
1448f3af935c417748c8aabd8a6623f628aac6b7dadc5c1f9c3ef010ff36df07
|
Provenance
The following attestation bundles were made for src_py_lib-0.1.4-py3-none-any.whl:
Publisher:
release.yml on sourcegraph/src-py-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
src_py_lib-0.1.4-py3-none-any.whl -
Subject digest:
d6325dfd85129dcc85f0474425ba2654698e77a539696f82e3595a3729e2e005 - Sigstore transparency entry: 1667517088
- Sigstore integration time:
-
Permalink:
sourcegraph/src-py-lib@12c4408dc4e7363c3d4214c37f815b993c97a5e9 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/sourcegraph
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@12c4408dc4e7363c3d4214c37f815b993c97a5e9 -
Trigger Event:
push
-
Statement type: