Skip to content

Commit 4412250

Browse files
committed
feat(examples): add PyPI usage demo
1 parent 220b3fd commit 4412250

5 files changed

Lines changed: 99 additions & 0 deletions

File tree

examples/pypi-basic/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.artifacts/

examples/pypi-basic/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Lance Context PyPI Example
2+
3+
This example project demonstrates how to install the `lance-context` package from PyPI and work with a context store using the Python API.
4+
5+
## Setup
6+
7+
Ensure Python 3.11 or newer is available locally.
8+
9+
### Using uv
10+
11+
```bash
12+
cd examples/pypi-basic
13+
uv venv
14+
source .venv/bin/activate
15+
uv pip install -e .
16+
```
17+
18+
### Using pip
19+
20+
```bash
21+
cd examples/pypi-basic
22+
python -m venv .venv
23+
source .venv/bin/activate
24+
pip install -e .
25+
```
26+
27+
## Run the demo
28+
29+
```bash
30+
uv run context-demo
31+
# or
32+
python -m context_example.main
33+
```
34+
35+
The script creates a Lance dataset under `.artifacts/` (ignored by git) and appends a short travel-planning conversation. It prints the current version, demonstrates time-travel by checking out an earlier version, and shows how you can reopen the dataset path to continue appending in future runs.

examples/pypi-basic/pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[build-system]
2+
requires = ["setuptools>=64"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "lance-context-example"
7+
version = "0.1.0"
8+
description = "Example project demonstrating the lance-context PyPI package."
9+
readme = "README.md"
10+
requires-python = ">=3.11"
11+
dependencies = ["lance-context>=0.1.0"]
12+
13+
[project.scripts]
14+
context-demo = "context_example.main:main"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .main import main
2+
3+
__all__ = ["main"]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
from uuid import uuid4
5+
6+
from lance_context import Context
7+
8+
9+
def main() -> None:
10+
project_root = Path(__file__).resolve().parent.parent.parent
11+
artifacts_dir = project_root / ".artifacts"
12+
artifacts_dir.mkdir(exist_ok=True)
13+
14+
dataset_path = artifacts_dir / f"travel_context_{uuid4().hex}.lance"
15+
ctx = Context.create(dataset_path.as_posix())
16+
print(f"Created context store at {dataset_path}")
17+
18+
ctx.add("system", "You are a friendly travel agent who compares destinations.")
19+
ctx.add("user", "Where should I travel in spring if I love street food?")
20+
ctx.add(
21+
"assistant",
22+
"Consider Osaka, Japan for cherry blossoms and the Kuromon market.",
23+
)
24+
25+
first_version = ctx.version()
26+
27+
ctx.add("user", "Any budget-friendly option in Europe?")
28+
ctx.add(
29+
"assistant",
30+
"Porto, Portugal offers great food, coastal views, and reasonable prices.",
31+
)
32+
33+
print(f"Entries stored: {ctx.entries()}")
34+
print(f"Current version: {ctx.version()}")
35+
36+
ctx.checkout(first_version)
37+
print(f"Rolled back to version {first_version}; entries now {ctx.entries()}")
38+
39+
print(
40+
"Re-run this script to create a fresh dataset, or reuse the printed path to "
41+
"append more entries from another process."
42+
)
43+
44+
45+
if __name__ == "__main__": # pragma: no cover - manual invocation
46+
main()

0 commit comments

Comments
 (0)