# graph


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

------------------------------------------------------------------------

### CodeGraph

``` python

def CodeGraph(
    path:str | pathlib.Path=':memory:'
):

```

*Call graph backed by apswutils SQLite.*

Storage: four tables in graph.db — graph_edges (caller, callee, kind,
confidence) graph_nodes (node, flavor, file, pagerank, …) co_dispatch
(group_id, node) file_index (path, root, last_analyzed_at)

``` python
self = CodeGraph(':memory:')
tables = {r[0] for r in self.db.execute("SELECT name FROM sqlite_master WHERE type='table'")}
assert {'graph_edges','graph_nodes','co_dispatch','file_index'} <= tables, f"Missing tables: {tables}"
print("schema ok:", tables)
```

    schema ok: {'graph_edges', 'co_dispatch', 'graph_nodes', 'file_index'}

------------------------------------------------------------------------

### static_edges

``` python

def static_edges(
    sources:dict=None, filenames:list=None, root:str=None
)->tuple:

```

*Static call edges via pyan3. Provide either filenames+root or sources
dict.*

------------------------------------------------------------------------

### dyn_edges

``` python

def dyn_edges(
    src:str, module:str
)->list:

```

*All dynamic dispatch edges: decorator, connect_body, registration,
co_dispatch.*

``` python
_SRC = '''
import flask
app = flask.Flask(__name__)

@app.route('/hello')
def hello(): pass

def setup(other_app):
    other_app.register(hello)
'''
edges = dyn_edges(_SRC, 'mymod')
kinds = {e['kind'] for e in edges}
assert 'decorator' in kinds, f"Expected decorator edge, got: {edges}"
assert 'registration' in kinds, f"Expected registration edge, got: {edges}"
assert dyn_edges('def (broken', 'bad') == L()
print("_dyn_edges ok:", edges)
```

    _dyn_edges ok: [{'caller': 'mymod.app', 'callee': 'mymod.hello', 'kind': 'decorator', 'confidence': 0.75}, {'caller': 'mymod.setup', 'callee': 'mymod.hello', 'kind': 'connect_body', 'confidence': 0.9}, {'caller': 'mymod.other_app', 'callee': 'mymod.hello', 'kind': 'registration', 'confidence': 0.75}]

``` python
_DELEGATES_SRC = '''
from fastcore.all import delegates

def target(x, y, z=1): pass

@delegates(target)
def wrapper_pos(**kw): pass

@delegates(to=target)
def wrapper_kw(**kw): pass

@delegates
def bare(**kw): pass

@delegates()
def empty(**kw): pass
'''
dyn_edges(_DELEGATES_SRC, 'mymod')
```

    [{'caller': 'mymod.wrapper_pos',
      'callee': 'mymod.target',
      'kind': 'delegates',
      'confidence': 0.85},
     {'caller': 'mymod.wrapper_kw',
      'callee': 'mymod.to=target',
      'kind': 'delegates',
      'confidence': 0.85}]

``` python
_PATCH_SRC = '''
from fastcore.all import patch, delegates
from apswutils.db import Database, Table, View

@patch
def basic(self:Database, x): pass

@patch(as_prop=True)
def prop(self:Database): pass

@patch(cls_method=True)
def cls_m(cls:Database): pass

@patch
def no_ann(self): pass

@patch
def union_m(self:Table|View): pass
'''
dyn_edges(_PATCH_SRC, 'mymod')
```

    [{'caller': 'mymod.Database',
      'callee': 'mymod.basic',
      'kind': 'patch',
      'confidence': 0.9},
     {'caller': 'mymod.Database',
      'callee': 'mymod.prop',
      'kind': 'patch',
      'confidence': 0.9},
     {'caller': 'mymod.Database',
      'callee': 'mymod.cls_m',
      'kind': 'patch',
      'confidence': 0.9},
     {'caller': 'mymod.Table',
      'callee': 'mymod.union_m',
      'kind': 'patch',
      'confidence': 0.9},
     {'caller': 'mymod.View',
      'callee': 'mymod.union_m',
      'kind': 'patch',
      'confidence': 0.9}]

``` python
edges, meta = static_edges({"mod": "def foo(): pass\ndef bar(): foo()"})
meta
```

    {'mod.foo': {'node': 'mod.foo', 'flavor': 'function', 'file': 'mod'},
     'mod.foo.^^^argument^^^': {'node': 'mod.foo.^^^argument^^^',
      'flavor': 'unspecified',
      'file': 'mod'},
     'mod.bar.^^^argument^^^': {'node': 'mod.bar.^^^argument^^^',
      'flavor': 'unspecified',
      'file': 'mod'},
     'mod.bar': {'node': 'mod.bar', 'flavor': 'function', 'file': 'mod'}}

``` python
assert all(k in edges[0] for k in ('caller','callee','kind','confidence'))
assert all(e['kind'] == 'static' for e in edges)
```

``` python
static_edges({"bad": "def (: !!!"})
```

    pyan3 static analysis failed: invalid syntax (bad, line 1)

    ([], {})

------------------------------------------------------------------------

### CodeGraph.from_sources

``` python

def from_sources(
    sources:dict
):

```

*Build from {module_name: source_str}.*

``` python
g_pr = CodeGraph(':memory:')
g_pr.db['graph_edges'].insert_all([
    {'caller':'A','callee':'B','kind':'static','confidence':1.0},
    {'caller':'B','callee':'C','kind':'static','confidence':1.0},
    {'caller':'A','callee':'C','kind':'static','confidence':1.0},
])
pr = _pagerank(g_pr.db)
print(pr)
assert 'C' in pr, "C should be in pagerank"
assert pr['C'] > pr['A'], f"C (most linked-to) should rank higher than A: {pr}"
print("pagerank ok:", pr)
```

    {'A': 0.05000000000000001, 'B': 0.07125000000000001, 'C': 0.13181250000000003}
    pagerank ok: {'A': 0.05000000000000001, 'B': 0.07125000000000001, 'C': 0.13181250000000003}

``` python
CodeGraph(':memory:').from_sources({'mod': 'def foo(): pass\ndef bar(): foo()\n'}).db.t.graph_nodes()
```

    [{'node': 'mod.foo',
      'flavor': 'function',
      'file': 'mod',
      'pagerank': 0.06938,
      'in_degree': 1,
      'out_degree': 0},
     {'node': 'mod.foo.^^^argument^^^',
      'flavor': 'unspecified',
      'file': 'mod',
      'pagerank': 0.0375,
      'in_degree': 0,
      'out_degree': 0},
     {'node': 'mod.bar.^^^argument^^^',
      'flavor': 'unspecified',
      'file': 'mod',
      'pagerank': 0.0375,
      'in_degree': 0,
      'out_degree': 0},
     {'node': 'mod.bar',
      'flavor': 'function',
      'file': 'mod',
      'pagerank': 0.0375,
      'in_degree': 0,
      'out_degree': 1}]

------------------------------------------------------------------------

### CodeGraph.from_pkg

``` python

def from_pkg(
    pkg:str, path:pathlib.Path | str='.', recursive:bool=True, symlinks:bool=True, file_glob:str=None,
    file_re:str=None, folder_re:str=None, skip_file_glob:str=None, skip_file_re:str=None, skip_folder_re:str=None,
    func:callable=join, ret_folders:bool=False, sort:bool=True, types:str | list=None, exts:str | list=None
)->CodeGraph:

```

*Build from an installed package. Uses pyan3 on the package source
files.*

------------------------------------------------------------------------

### CodeGraph.from_file

``` python

def from_file(
    path:str | pathlib.Path
)->CodeGraph:

```

*Build from a single .py file. Module name derived from filename.*

------------------------------------------------------------------------

### CodeGraph.from_dir

``` python

def from_dir(
    dir:str | pathlib.Path, path:pathlib.Path | str='.', recursive:bool=True, symlinks:bool=True, file_glob:str=None,
    file_re:str=None, folder_re:str=None, skip_file_glob:str=None, skip_file_re:str=None, skip_folder_re:str=None,
    func:callable=join, ret_folders:bool=False, sort:bool=True, types:str | list=None, exts:str | list=None
)->CodeGraph:

```

*Build from .py files under path — pyan reads files directly.*

------------------------------------------------------------------------

### CodeGraph.process_files

``` python

def process_files(
    files, root:NoneType=None
):

```

*Call self as a function.*

``` python
cg=CodeGraph(':memory:').from_pkg('httpx').from_pkg('fastcore').from_pkg('litesearch').from_pkg('fastlite').from_pkg('apswutils')
```

``` python
cg.db.t.graph_nodes(select='*', where='node="httpx._api.request"',limit=3)
```

    [{'node': 'httpx._api.request',
      'flavor': 'function',
      'file': '/Users/71293/code/personal/orgs/kosha/.venv/lib/python3.13/site-packages/httpx/_api.py',
      'pagerank': 8e-05,
      'in_degree': 8,
      'out_degree': 22}]

``` python
cg.from_dir('../kosha')
```

    <__main__.CodeGraph>

``` python
cg.db.t.graph_nodes.count
```

    11421

``` python
cg.gn('node like "%emb_doc%"')
```

    [{'node': 'kosha.core.emb_doc',
      'flavor': 'function',
      'file': '../kosha/core.py',
      'pagerank': 0.00012,
      'in_degree': 0,
      'out_degree': 0}]

------------------------------------------------------------------------

### CodeGraph.node_info

``` python

def node_info(
    node:str, with_kind:bool=False
)->dict:

```

*Call self as a function.*

------------------------------------------------------------------------

### CodeGraph.edge_kinds

``` python

def edge_kinds(
    
)->dict:

```

*Call self as a function.*

------------------------------------------------------------------------

### CodeGraph.short_paths

``` python

def short_paths(
    nodes, k:int=10
)->L:

```

*Shortest paths between all pairs in top-k nodes via combinations.*

------------------------------------------------------------------------

### CodeGraph.short_path

``` python

def short_path(
    src:str, tgt:str
)->L:

```

*Shortest path from src to tgt via recursive CTE. Returns L of node
names.*

------------------------------------------------------------------------

### CodeGraph.ranked

``` python

def ranked(
    k:int=10, module:str=None
)->L:

```

*Top-k nodes by pagerank, optionally filtered to a module prefix.*

------------------------------------------------------------------------

### CodeGraph.co_dispatched

``` python

def co_dispatched(
    node:str
)->L:

```

*Call self as a function.*

------------------------------------------------------------------------

### CodeGraph.neighbors

``` python

def neighbors(
    n:str, depth:int=1
)->L:

```

*callers + callees up to depth hops.*

------------------------------------------------------------------------

### CodeGraph.callees

``` python

def callees(
    n:str, with_kind:bool=False
)->L:

```

*Call self as a function.*

------------------------------------------------------------------------

### CodeGraph.callers

``` python

def callers(
    n:str, with_kind:bool=False
)->L:

```

*Call self as a function.*

``` python
cg.db.t.graph_edges(where='caller like "%apswutils.db.Table.insert_all%" and callee like "%insert_chunk%"')
```

    [{'id': 15617,
      'caller': 'apswutils.db.Table.insert_all',
      'callee': 'apswutils.db.Table.insert_chunk',
      'kind': 'static',
      'confidence': 1.0}]

``` python
to_date_co = cg.co_dispatched('fastcore.basics.to_date')
assert all('fastcore' in n for n in to_date_co), \
    f"fastcore.basics.to_date co_dispatched leaked into httpx: {to_date_co}"
assert len(to_date_co) > 0, "fastcore.basics.to_date should have co_dispatched peers"
print("co_dispatched cross-package isolation ok:", to_date_co)
```

    co_dispatched cross-package isolation ok: ['fastcore.basics.to_int', 'fastcore.basics.to_bool', 'fastcore.basics.to_float']

``` python
cg.node_info('fastcore.basics.to_date')
```

    {'node': 'fastcore.basics.to_date',
     'flavor': 'function',
     'file': '/Users/71293/code/personal/orgs/kosha/.venv/lib/python3.13/site-packages/fastcore/basics.py',
     'pagerank': 3e-05,
     'in_degree': 0,
     'out_degree': 4,
     'callers': [],
     'callees': ['None.str', 'None.isinstance', 'fastcore.basics._typeerr', 'fastcore.basics.str2date'],
     'co_dispatched': ['fastcore.basics.to_int', 'fastcore.basics.to_bool', 'fastcore.basics.to_float']}

``` python
n = cg.db.t.graph_nodes(where='node like "%mk_write"')[0]['node']
cg.node_info(n)
```

    {'node': 'fastcore.xtras.mk_write',
     'flavor': 'function',
     'file': '/Users/71293/code/personal/orgs/kosha/.venv/lib/python3.13/site-packages/fastcore/xtras.py',
     'pagerank': 3e-05,
     'in_degree': 2,
     'out_degree': 7,
     'callers': ['fastcore.xtras.write_json', 'fastcore.xtras.Path'],
     'callees': ['None.parent', 'fastcore.basics.patch', 'None.chown', 'None.NoneType', 'None.write_text', 'None.Path', 'None.int'],
     'co_dispatched': []}

``` python
cg.short_path('apswutils.db.Table.upsert', 'apswutils.db.Table.insert_chunk')
```

    ['apswutils.db.Table.upsert', 'apswutils.db.Table.upsert_all', 'apswutils.db.Table.insert_all', 'apswutils.db.Table.insert_chunk']

``` python
cg.ranked(5, module='litesearch')
```

    [{'node': 'litesearch.data.kw', 'pagerank': 0.00064}, {'node': 'litesearch.utils.FastEncode._load_tok.listcomp.0', 'pagerank': 0.00034}, {'node': 'litesearch.utils.encode_pdf_images.listcomp.1', 'pagerank': 0.00034}, {'node': 'litesearch.core.vec_search', 'pagerank': 0.00033}, {'node': 'litesearch.data.file_parse.meta_', 'pagerank': 0.00033}]

``` python
cg.callers('litesearch.data.kw')
```

    ['litesearch.core.get_store', 'litesearch.core.database', 'litesearch.data.pkg2chunks', 'litesearch.data.pre', 'litesearch.utils.FastEncode.encode', 'litesearch.utils.FastEncode.encode.lambda.0', 'litesearch.utils.FastEncode.encode_document', 'litesearch.utils.FastEncode.encode_query', 'litesearch.utils.FastEncodeImage.embed', 'litesearch.utils.FastEncodeImage.embed.lambda.0', 'litesearch.utils.FastEncodeMultimodal.encode_text', 'litesearch.utils.FastEncodeMultimodal.encode_image', 'litesearch.utils.encode_pdf_texts']

------------------------------------------------------------------------

### CodeGraph.file2nodes

``` python

def file2nodes(
    path:str
)->set:

```

*Return set of node names whose file column matches path.*

``` python
g_drop = CodeGraph(':memory:')
g_drop.db.t.graph_nodes.insert_all([
    {'node':'mod.foo','flavor':'function','file':'/proj/mod.py'},
    {'node':'mod.bar','flavor':'function','file':'/proj/mod.py'},
])
g_drop.db.t.graph_edges.insert({'caller':'mod.foo','callee':'mod.bar','kind':'static','confidence':1.0})
assert g_drop.file2nodes('/proj/mod.py') == {'mod.foo','mod.bar'}
g_drop._drop_file('/proj/mod.py')
assert g_drop.file2nodes('/proj/mod.py') == set()
assert not list(g_drop.db.execute("SELECT * FROM graph_edges"))
print("_drop_file + _nodes_for_file ok")
```

    _drop_file + _nodes_for_file ok

------------------------------------------------------------------------

### CodeGraph.sync

``` python

def sync(
    dir:NoneType=None, pkgs:NoneType=None
)->CodeGraph:

```

*Incremental sync: from_dir per dir, from_pkg per pkg; manage
file_index.*

------------------------------------------------------------------------

### CodeGraph.sync_pkgs

``` python

def sync_pkgs(
    pkgs:list
)->CodeGraph:

```

*Incremental sync for packages: drop missing files, update changed
files, add new files.*

------------------------------------------------------------------------

### CodeGraph.sync_dir

``` python

def sync_dir(
    dir:str | pathlib.Path
)->CodeGraph:

```

*Incremental sync for a directory: drop missing files, update changed
files, add new files.*

``` python
import tempfile, time

with tempfile.TemporaryDirectory() as tmp:
    pa, pb = Path(f'{tmp}/a.py'), Path(f'{tmp}/b.py')
    pa.write_text('def foo(): pass\n'); pb.write_text('def bar(): pass\n')

    g = CodeGraph(':memory:')
    g.sync(dir=tmp)
    fi = {r['path']: r['last_analyzed_at'] for r in g.db.t.file_index.rows}
    assert str(pa) in fi and str(pb) in fi, fi

    # Modify b.py — mtime changes
    time.sleep(0.01)
    pb.write_text('def bar(): return 42\n')
    pb.touch()  # ensure mtime update
    g.sync(dir=tmp)
    fi2 = {r['path']: r['last_analyzed_at'] for r in g.db.t.file_index.rows}
    assert fi2[str(pa)] == fi[str(pa)], f"a.py should not be reprocessed: {fi2}"
    assert fi2[str(pb)] != fi[str(pb)], f"b.py should be reprocessed: {fi2}"

    # Delete a.py — should be removed from file_index
    pa.unlink()
    g.sync(dir=tmp)
    fi3 = {r['path'] for r in g.db.t.file_index.rows}
    assert str(pa) not in fi3, f"a.py should be removed: {fi3}"
    print("sync incremental ok, remaining files:", fi3)

    # add packages to codegraph
    g.sync(pkgs=['httpx', 'fastcore'])
    fi4 = {r['path'] for r in g.db.t.file_index.rows}
    assert any('httpx' in p for p in fi4), f"httpx files should be indexed: {fi4}"
    assert any('fastcore' in p for p in fi4), f"fastcore files should be indexed: {fi4}"
    print("sync_pkgs ok, indexed packages:", fi4)
```

    no action. pkgs empty
    no action. pkgs empty
    no action. pkgs empty
    sync incremental ok, remaining files: {'/tmp/tmpphfek2l5/b.py'}
    no action. dir empty
    sync_pkgs ok, indexed packages: {'/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_transports/wsgi.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_urls.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_transports/default.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_decoders.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/all.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/parallel.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/net.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/foundation.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/basics.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/docscrape.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/py2pyi.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/__init__.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/shutil.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/__version__.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/imghdr.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/docments.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/style.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_transports/mock.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/transform.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_api.py', '/tmp/tmpphfek2l5/b.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/test.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_models.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_status_codes.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_utils.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/imports.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_transports/base.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_content.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_main.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/tools.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/_modidx.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_urlparse.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/utils.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_auth.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/nbio.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/script.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/xdg.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/xtras.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_types.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_multipart.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/nb_imports.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_exceptions.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_config.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_transports/asgi.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/__init__.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_transports/__init__.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/dispatch.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/meta.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/httpx/_client.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/xml.py', '/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/fastcore/ansi.py'}

------------------------------------------------------------------------

### Kosha.short_paths

``` python

def short_paths(
    
):

```

*Shortest paths helper: shortest paths between all pairs in top-k
nodes.*

------------------------------------------------------------------------

### Kosha.short_path

``` python

def short_path(
    
):

```

*Shortest path helper: shortest path between two nodes.*

------------------------------------------------------------------------

### Kosha.neighbors

``` python

def neighbors(
    
):

```

*Neighbors helper: callers + callees up to depth hops.*

------------------------------------------------------------------------

### Kosha.ni

``` python

def ni(
    
):

```

*Node info helper: graph_nodes row + callers, callees, co-dispatched
nodes.*

------------------------------------------------------------------------

### Kosha.ge

``` python

def ge(
    
):

```

*graph_edges table for direct queries.*

------------------------------------------------------------------------

### Kosha.gn

``` python

def gn(
    
):

```

*graph_nodes table for direct queries.*

------------------------------------------------------------------------

### Kosha.graphdb

``` python

def graphdb(
    
):

```

*Underlying graph.db database for direct queries.*

------------------------------------------------------------------------

### Kosha.graph

``` python

def graph(
    
)->CodeGraph:

```

*code graph for this kosha instance*

------------------------------------------------------------------------

### Kosha.context

``` python

def context(
    q:str, # query with optional key:value filters
    limit:int=50, repo:bool=True, env:bool=True, graph:bool=True, columns:str='content,metadata', sys_wide:bool=True,
    kw:VAR_KEYWORD
)->L: # forwarded to env_context / repo_context

```

*Fan-out semantic search: parse filters, run repo + env searches, merge
with chained RRF.*

------------------------------------------------------------------------

### Kosha.sync

``` python

def sync(
    pkgs:NoneType=None, dir:NoneType=None, emb:function=embedder, verbose:bool=True, in_parallel:bool=False
)->Kosha:

```

*Sync code store, env store, and code graph. Runs in a daemon thread by
default.*

``` python
k = Kosha(xdg_dir=Path('.'))
```

``` python
k.sync(pkgs=['httpx', 'fastcore', 'litesearch','fastlite','apswutils','python-fasthtml','apsw','ghapi'])
```

    syncing files [Path('/Users/71293/code/personal/orgs/kosha/kosha/core.py'), Path('/Users/71293/code/personal/orgs/kosha/kosha/graph.py')] .....
    synced repo                                                          
    loading pkgs {'fastlite', 'httpx', 'ghapi', 'fastcore', 'apswutils', 'python-fasthtml', 'apsw', 'litesearch'} ......

    Updating packages:   0%|          | 0/8 [00:00<?, ?pkg/s]

    updating pkg: fastlite ...
    package [{'name': 'fastlite', 'version': '0.2.4'}] already loaded.
    updating pkg: httpx ...
    package [{'name': 'httpx', 'version': '0.28.1'}] already loaded.
    updating pkg: ghapi ...

    Updating packages: 100%|██████████| 8/8 [00:00<00:00, 60.17pkg/s]

    package [{'name': 'ghapi', 'version': '1.0.13'}] already loaded.
    updating pkg: fastcore ...
    package [{'name': 'fastcore', 'version': '1.12.40'}] already loaded.
    updating pkg: apswutils ...
    package [{'name': 'apswutils', 'version': '0.1.2'}] already loaded.
    updating pkg: python-fasthtml ...
    package [{'name': 'python-fasthtml', 'version': '0.13.3'}] already loaded.
    updating pkg: apsw ...
    package [{'name': 'apsw', 'version': '3.53.0.0'}] already loaded.
    updating pkg: litesearch ...
    package [{'name': 'litesearch', 'version': '0.0.23'}] already loaded.

    [None, None, <__main__.CodeGraph object>]

``` python
k.sync(in_parallel=True)
```

    loading pkgs {'fastlite', 'pillow', 'model2vec', 'pdf_oxide', 'fastcore', 'onnxruntime', 'anyio', 'notebook', 'yake', 'litesearch', 'Jinja2', 'pyan3', 'tokenizers', 'pandas', 'codesigs', 'chonkie', 'python-fasthtml', 'watchfiles', 'fastprogress', 'usearch'} ......

    Updating packages:  20%|██        | 4/20 [00:00<00:00, 35.32pkg/s]

    updating pkg: fastlite ...
    no action. pkgs empty
    package [{'name': 'fastlite', 'version': '0.2.4'}] already loaded.
    updating pkg: pillow ...
    package [{'name': 'pillow', 'version': '12.2.0'}] already loaded.
    updating pkg: model2vec ...
    package [{'name': 'model2vec', 'version': '0.8.1'}] already loaded.
    updating pkg: pdf_oxide ...
    package [{'name': 'pdf_oxide', 'version': '0.3.37'}] already loaded.
    updating pkg: fastcore ...
    package [{'name': 'fastcore', 'version': '1.12.40'}] already loaded.
    updating pkg: onnxruntime ...
    package [{'name': 'onnxruntime', 'version': '1.24.4'}] already loaded.
    updating pkg: anyio ...
    package [{'name': 'anyio', 'version': '4.13.0'}] already loaded.

    Updating packages:  60%|██████    | 12/20 [00:00<00:00, 32.23pkg/s]

    updating pkg: notebook ...
    package [{'name': 'notebook', 'version': '7.5.5'}] already loaded.
    updating pkg: yake ...
    package [{'name': 'yake', 'version': '0.7.3'}] already loaded.
    updating pkg: litesearch ...
    package [{'name': 'litesearch', 'version': '0.0.23'}] already loaded.
    updating pkg: Jinja2 ...
    package [{'name': 'Jinja2', 'version': '3.1.6'}] already loaded.
    updating pkg: pyan3 ...
    package [{'name': 'pyan3', 'version': '2.5.0'}] already loaded.
    updating pkg: tokenizers ...

    Updating packages: 100%|██████████| 20/20 [00:00<00:00, 33.21pkg/s]

    package [{'name': 'tokenizers', 'version': '0.22.2'}] already loaded.
    updating pkg: pandas ...
    package [{'name': 'pandas', 'version': '3.0.2'}] already loaded.
    updating pkg: codesigs ...
    package [{'name': 'codesigs', 'version': '0.0.2'}] already loaded.
    updating pkg: chonkie ...
    package [{'name': 'chonkie', 'version': '1.6.4'}] already loaded.
    updating pkg: python-fasthtml ...
    package [{'name': 'python-fasthtml', 'version': '0.13.3'}] already loaded.
    updating pkg: watchfiles ...
    package [{'name': 'watchfiles', 'version': '1.1.1'}] already loaded.
    updating pkg: fastprogress ...
    package [{'name': 'fastprogress', 'version': '1.1.5'}] already loaded.
    updating pkg: usearch ...
    package [{'name': 'usearch', 'version': '2.25.1'}] already loaded.

    [None, None, <__main__.CodeGraph>]

``` python
k.gn(where='node like "fastcore.basics.me%"', limit=1)
```

    [{'node': 'fastcore.basics.merge.str',
      'flavor': 'attribute',
      'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/basics.py',
      'pagerank': 3e-05,
      'in_degree': 0,
      'out_degree': 0}]

``` python
k.graph.ranked(module='fastcore.basics')
```

    [{'node': 'fastcore.basics.patch', 'pagerank': 0.00089}, {'node': 'fastcore.basics.NS.__iter__', 'pagerank': 0.00056}, {'node': 'fastcore.basics.NotStr.__iter__', 'pagerank': 0.00056}, {'node': 'fastcore.basics.GetAttr', 'pagerank': 0.00035}, {'node': 'fastcore.basics.NotStr', 'pagerank': 0.0003}, {'node': 'fastcore.basics.listify', 'pagerank': 0.00025}, {'node': 'fastcore.basics.NS', 'pagerank': 0.0002}, {'node': 'fastcore.basics.adict', 'pagerank': 0.00018}, {'node': 'fastcore.basics.AttrDict', 'pagerank': 0.00017}, {'node': 'fastcore.basics.not_._f', 'pagerank': 0.00014}]

``` python
k.ni('fastcore.basics.merge')
```

    {'node': 'fastcore.basics.merge',
     'flavor': 'function',
     'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/basics.py',
     'pagerank': 3e-05,
     'in_degree': 1,
     'out_degree': 12,
     'callers': ['fastcore.script.call_parse._f'],
     'callees': ['fastcore.docscrape.NumpyDocString.__iter__', 'fastcore.nbio.Notebook.__iter__', 'fastcore.xtras.IterLen.__iter__', 'fastcore.basics.NotStr.__iter__', 'None.__next__', 'fastcore.xml.FT.__iter__', 'None.ds', 'fastcore.basics.NS.__iter__', 'fastcore.foundation.CollBase.__iter__', 'fastcore.xtras._save_iter.__iter__', 'fastcore.xtras.CachedIter.__iter__', 'fastcore.xtras.SaveReturn.__iter__'],
     'co_dispatched': []}

``` python
first(k.context('how do I merge dicts package:fastcore path:basics', limit=1))
```

``` python
{ '_rrf_score': 0.016666666666666666,
  '_src_id': 'env:641',
  'callees': ['fastcore.docscrape.NumpyDocString.__iter__', 'fastcore.nbio.Notebook.__iter__', 'fastcore.xtras.IterLen.__iter__', 'fastcore.basics.NotStr.__iter__', 'None.__next__', 'fastcore.xml.FT.__iter__', 'None.ds', 'fastcore.basics.NS.__iter__', 'fastcore.foundation.CollBase.__iter__', 'fastcore.xtras._save_iter.__iter__', 'fastcore.xtras.CachedIter.__iter__', 'fastcore.xtras.SaveReturn.__iter__'],
  'callers': ['fastcore.script.call_parse._f'],
  'co_dispatched': [],
  'content': 'def merge(*ds):\n'
             '    "Merge all dictionaries in `ds`"\n'
             '    return {k:v for d in ds if d is not None for k,v in '
             'd.items()}',
  'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/basics.py',
  'flavor': 'function',
  'in_degree': 1,
  'metadata': { 'end_lineno': 657,
                'lang': '.py',
                'lineno': 655,
                'mod_name': 'fastcore.basics.merge',
                'name': 'merge',
                'package': 'fastcore',
                'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/basics.py',
                'type': 'FunctionDef',
                'uploaded_at': 1776124140.6147513,
                'version': '1.12.39'},
  'node': 'fastcore.basics.merge',
  'out_degree': 12,
  'pagerank': 3e-05,
  'rank': -10.449557921383162,
  'rowid': 641}
```

------------------------------------------------------------------------

### Kosha.task_context

``` python

def task_context(
    q:str, depth:int=3, limit:int=10
)->dict:

```

*Structured context: candidate packages → dep stack → graph entry points
→ call paths.*

------------------------------------------------------------------------

### Kosha.dep_stack

``` python

def dep_stack(
    seeds:list=None, depth:int=1
)->list:

```

*BFS over pkg_deps, ordered by coupling strength.*

``` python
# dep_stack smoke test
k2 = Kosha(xdg_dir=Path('.'))
k2.update_pkg('fastlite')
rows = list(k2.envdb.t.pkg_deps(where='from_pkg="fastlite"'))
assert rows, 'pkg_deps should have rows after update_pkg'
assert any(r['to_pkg'] in ('fastcore','fastlite') for r in rows), f'expected fastcore/fastlite: {rows[:3]}'
print('pkg_deps via update_pkg ok:', rows[:3])
```

    pkg_deps via update_pkg ok: [{'from_pkg': 'fastlite', 'to_pkg': 'apsw', 'n_modules': 1}, {'from_pkg': 'fastlite', 'to_pkg': 'apswutils', 'n_modules': 2}, {'from_pkg': 'fastlite', 'to_pkg': 'dataclasses', 'n_modules': 2}]

``` python
layers = k2.dep_stack(['fastlite'])
print(layers)
print('\n\n-------------------------------------------------\n\n')
stack = L(layers).flatten()
assert 'fastcore' in stack, f'fastcore should be in dep_stack: {stack}'
print('_dep_stack ok:', stack)
```

    [['fastlite'], ['apswutils', 'dataclasses', 'enum', 'typing', 'fastcore', 'inspect', 'types', 'apsw']]


    -------------------------------------------------


    _dep_stack ok: ['fastlite', 'apswutils', 'dataclasses', 'enum', 'typing', 'fastcore', 'inspect', 'types', 'apsw']

``` python
tc = k2.task_context('payments page monsterui fasthtml')
print('task_context packages:', tc['packages'])
print('task_context dep_stack:', tc['dep_layers'])
```

    task_context packages: ['fastcore', 'httpx', 'fastlite', 'apsw', 'ghapi', 'apswutils', 'litesearch']
    task_context dep_stack: [['fastcore', 'httpx', 'fastlite', 'apsw', 'ghapi', 'apswutils', 'litesearch'], ['typing', 'os', 're', 'inspect', 'sys', 'functools', 'json', 'time', 'contextlib', 'collections', 'types', 'io', 'dataclasses', 'enum', 'urllib', 'importlib', 'warnings', 'random', 'argparse', 'ast', 'textwrap', 'math', 'copy', 'itertools', 'datetime', 'tempfile', 'pathlib', 'shutil', 'base64', 'contextvars', 'ssl', 'numpy', 'subprocess', 'html', 'asyncio', 'pprint', 'logging', 'codecs', 'fnmatch', 'csv', 'PIL', 'threading', 'shlex', 'traceback', 'mimetypes', 'http', 'pickle', 'hashlib', 'pdf_oxide', 'ipaddress', 'webbrowser', 'socket', 'xml', 'gzip', 'usearch', 'idna', 'atexit', 'difflib', 'uuid', 'string', 'struct', 'httpcore', 'fractions', 'certifi', 'resource', 'builtins', 'decimal', 'getpass', 'weakref', 'tokenize', 'pygments', 'readline', 'tomllib', 'queue', 'abc', 'tokenizers', 'onnxruntime', 'wcwidth', 'click', 'email', 'sqlite3', 'operator', 'numbers', 'netrc', 'gc', 'codesigs', 'pandas', 'platform', 'statistics', 'zlib', 'configparser', 'concurrent', 'termios', 'tty', 'binascii', 'rich', 'yake', 'IPython', 'unicodedata', 'ctypes', 'keyword', 'bz2', 'chonkie', 'zipfile', 'anyio', 'code', 'pdb', 'huggingface_hub', 'secrets', 'yaml', 'multiprocessing', 'glob']]

``` python
k2.context('payments page monsterui fasthtml', repo=False)[:10]
```

    [{'rowid': 1068, 'content': 'def _repr_html_(self:FT): return self.__html__()', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'uploaded_at': 1776124140.6237516, 'name': '_repr_html_', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 224, 'end_lineno': 224, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.xml._repr_html_'}, '_dist': 0.7265547513961792, '_rrf_score': 0.016666666666666666, '_src_id': 'env:1068', 'node': 'fastcore.xml._repr_html_', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'pagerank': 0.00013, 'in_degree': 1, 'out_degree': 4, 'callers': ['fastcore.xml.FT'], 'callees': ['fastcore.xml.__html__', 'fastcore.basics.patch', 'fastcore.xml.FT', 'fastcore.xml.Safe.__html__'], 'co_dispatched': []}, {'rowid': 1067, 'content': 'def __html__(self:FT): return to_xml(self, indent=False)', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'uploaded_at': 1776124140.6237516, 'name': '__html__', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 219, 'end_lineno': 219, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.xml.__html__'}, '_dist': 0.7330434918403625, '_rrf_score': 0.01639344262295082, '_src_id': 'env:1067', 'node': 'fastcore.xml.__html__', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'pagerank': 0.00018, 'in_degree': 6, 'out_degree': 3, 'callers': ['fastcore.xml._escape', 'fastcore.xml._noescape', 'fastcore.xml._to_attr', 'fastcore.xml._repr_html_', 'fastcore.xtras.hl_md', 'fastcore.xml.FT'], 'callees': ['fastcore.basics.patch', 'fastcore.xml.FT', 'fastcore.xml.to_xml'], 'co_dispatched': []}, {'rowid': 1060, 'content': 'def Html(*c, doctype=True, **kwargs)->FT:\n    "An HTML tag, optionally preceeded by `!DOCTYPE HTML`"\n    res = ft(\'html\', *c, **kwargs)\n    if not doctype: return res\n    return (ft(\'!DOCTYPE\', html=True, void_=True), res)', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'uploaded_at': 1776124140.6237516, 'name': 'Html', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 128, 'end_lineno': 132, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.xml.Html'}, '_dist': 0.7629344463348389, '_rrf_score': 0.016129032258064516, '_src_id': 'env:1060', 'node': 'fastcore.xml.Html', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'pagerank': 3e-05, 'in_degree': 0, 'out_degree': 5, 'callers': [], 'callees': ['None.bool', 'fastcore.script.Param.kwargs', 'fastcore.xml.ft', 'fastcore.xml.FT', 'None.c'], 'co_dispatched': []}, {'rowid': 1073, 'content': 'def showtags(s):\n    return f"""<code><pre>\n{escape(to_xml(s))}\n</code></pre>"""', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'uploaded_at': 1776124140.6237516, 'name': 'showtags', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 248, 'end_lineno': 251, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.xml.showtags'}, '_dist': 0.7673101425170898, '_rrf_score': 0.015873015873015872, '_src_id': 'env:1073', 'node': 'fastcore.xml.showtags', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'pagerank': 3e-05, 'in_degree': 0, 'out_degree': 2, 'callers': [], 'callees': ['None.escape', 'fastcore.xml.to_xml'], 'co_dispatched': []}, {'rowid': 1061, 'content': 'class Safe(str):\n    def __html__(self): return self', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'uploaded_at': 1776124140.6237516, 'name': 'Safe', 'lang': '.py', 'type': 'ClassDef', 'lineno': 135, 'end_lineno': 136, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.xml.Safe'}, '_dist': 0.7769165635108948, '_rrf_score': 0.015625, '_src_id': 'env:1061', 'node': 'fastcore.xml.Safe', 'flavor': 'class', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'pagerank': 3e-05, 'in_degree': 2, 'out_degree': 1, 'callers': ['fastcore.xml._to_xml', 'fastcore.xml.to_xml'], 'callees': ['None.str'], 'co_dispatched': []}, {'rowid': 217, 'content': 'def _ref(pay, pre=\'\'): return f\'{pre} "{pay.ref.split("/")[-1]}"\' if pay.ref else \'\'', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/event.py', 'uploaded_at': 1773452878.263642, 'name': '_ref', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 152, 'end_lineno': 152, 'package': 'ghapi', 'version': '1.0.13', 'mod_name': 'ghapi.event._ref'}, '_dist': 0.7785882949829102, '_rrf_score': 0.015384615384615385, '_src_id': 'env:217', 'node': 'ghapi.event._ref', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/event.py', 'pagerank': 0.00024, 'in_degree': 2, 'out_degree': 2, 'callers': ['ghapi.event._ref_detl', 'ghapi.event.description'], 'callees': ['None.ref', 'None.str'], 'co_dispatched': []}, {'rowid': 21, 'content': "def chunk_texts(text:str):\n\t'Chunk texts using Fast Chunker'\n\tfrom chonkie import FastChunker\n\treturn L(FastChunker(delimiters='\\n\\n')(text)).map(lambda c: c.text)", 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/litesearch/data.py', 'uploaded_at': 1776728074.0431254, 'name': 'chunk_texts', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 128, 'end_lineno': 131, 'package': 'litesearch', 'version': '0.0.22', 'mod_name': 'litesearch.data.chunk_texts'}, '_dist': 0.7848308682441711, '_rrf_score': 0.015151515151515152, '_src_id': 'env:21', 'node': 'litesearch.data.chunk_texts', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/litesearch/data.py', 'pagerank': 0.0002, 'in_degree': 2, 'out_degree': 6, 'callers': ['litesearch.data.file_parse', 'litesearch.data.file_parse'], 'callees': ['None.FastChunker', 'None.L', 'None.str', 'None.L', 'None.FastChunker', 'None.str'], 'co_dispatched': []}, {'rowid': 445, 'content': 'def encode_html(html: str) -> tuple[dict[str, str], ByteStream]:\n    body = html.encode("utf-8")\n    content_length = str(len(body))\n    content_type = "text/html; charset=utf-8"\n    headers = {"Content-Length": content_length, "Content-Type": content_type}\n    return headers, ByteStream(body)', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/httpx/_content.py', 'uploaded_at': 1773452878.069788, 'name': 'encode_html', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 168, 'end_lineno': 173, 'package': 'httpx', 'version': '0.28.1', 'mod_name': 'httpx._content.encode_html'}, '_dist': 0.7889260053634644, '_rrf_score': 0.014925373134328358, '_src_id': 'env:445', 'node': 'httpx._content.encode_html', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/httpx/_content.py', 'pagerank': 5e-05, 'in_degree': 1, 'out_degree': 7, 'callers': ['httpx._content.encode_response'], 'callees': ['None.str', 'None.encode', 'None.tuple', 'None.dict', 'None.len', 'httpx._content.ByteStream', 'httpx._content.ByteStream.__init__'], 'co_dispatched': []}, {'rowid': 563, 'content': 'def _htmlconverter(fg, bg, bold, underline, inverse):\n    "Return start and end tags for given foreground/background/bold/underline."\n    if (fg, bg, bold, underline, inverse) == (None, None, False, False, False): return "", ""\n\n    classes,styles = [],[]\n    if inverse: fg, bg = bg, fg\n    if isinstance(fg, int): classes.append(_ANSI_COLORS[fg] + "-fg")\n    elif fg: styles.append("color: rgb({},{},{})".format(*fg))\n    elif inverse: classes.append("ansi-default-inverse-fg")\n\n    if isinstance(bg, int): classes.append(_ANSI_COLORS[bg] + "-bg")\n    elif bg: styles.append("background-color: rgb({},{},{})".format(*bg))\n    elif inverse: classes.append("ansi-default-inverse-bg")\n\n    if bold: classes.append("ansi-bold")\n    if underline: classes.append("ansi-underline")\n\n    starttag = "<span"\n    if classes: starttag += \' class="\' + " ".join(classes) + \'"\'\n    if styles: starttag += \' style="\' + "; ".join(styles) + \'"\'\n    starttag += ">"\n    return starttag, "</span>"', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/ansi.py', 'uploaded_at': 1776124140.6143115, 'name': '_htmlconverter', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 39, 'end_lineno': 60, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.ansi._htmlconverter'}, '_dist': 0.8005787134170532, '_rrf_score': 0.014705882352941176, '_src_id': 'env:563', 'node': 'fastcore.ansi._htmlconverter', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/ansi.py', 'pagerank': 4e-05, 'in_degree': 1, 'out_degree': 5, 'callers': ['fastcore.ansi.ansi2html'], 'callees': ['None.int', 'None.str', 'None.format', 'None.join', 'None.isinstance'], 'co_dispatched': []}, {'rowid': 1043, 'content': 'def __getattr__(name):\n     raise ImportError(\n         f"Could not import \'{name}\' from fastcore.transform - this module has been moved to the fasttransform package.\\n"\n         "To migrate your code, please see the migration guide at: https://answerdotai.github.io/fasttransform/fastcore_migration_guide.html"\n     )', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/transform.py', 'uploaded_at': 1776124140.6230223, 'name': '__getattr__', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 1, 'end_lineno': 5, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.transform.__getattr__'}, '_dist': 0.8097614049911499, '_rrf_score': 0.014492753623188406, '_src_id': 'env:1043', 'node': 'fastcore.transform.__getattr__', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/transform.py', 'pagerank': 3e-05, 'in_degree': 0, 'out_degree': 1, 'callers': [], 'callees': ['None.ImportError'], 'co_dispatched': []}]

``` python
k2.context('payments page packages:monsterui,python-fasthtml', repo=False)[:10]
```

    [{'rowid': 1073, 'content': 'def showtags(s):\n    return f"""<code><pre>\n{escape(to_xml(s))}\n</code></pre>"""', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'uploaded_at': 1776124140.6237516, 'name': 'showtags', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 248, 'end_lineno': 251, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.xml.showtags'}, '_dist': 0.7440280914306641, '_rrf_score': 0.016666666666666666, '_src_id': 'env:1073', 'node': 'fastcore.xml.showtags', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/xml.py', 'pagerank': 3e-05, 'in_degree': 0, 'out_degree': 2, 'callers': [], 'callees': ['None.escape', 'fastcore.xml.to_xml'], 'co_dispatched': []}, {'rowid': 205, 'content': 'def enable_pages(self:GhApi, branch=None, path="/"):\n    "Enable or update pages for a repo to point to a `branch` and `path`."\n    if path not in (\'/docs\',\'/\'): raise Exception("path not in (\'/docs\',\'/\')")\n    r = self.repos.get()\n    branch = branch or r.default_branch\n    source = {"branch": branch, "path": path}\n    if r.has_pages: return # self.repos.update_information_about_pages_site(source=source)\n    if len(self.list_branches(branch))==0: self.create_branch_empty(branch)\n    return self.repos.create_pages_site(source=source)', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/core.py', 'uploaded_at': 1773452878.2580557, 'name': 'enable_pages', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 337, 'end_lineno': 345, 'package': 'ghapi', 'version': '1.0.13', 'mod_name': 'ghapi.core.enable_pages'}, '_dist': 0.7736147046089172, '_rrf_score': 0.01639344262295082, '_src_id': 'env:205', 'node': 'ghapi.core.enable_pages', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/core.py', 'pagerank': 0.0002, 'in_degree': 1, 'out_degree': 11, 'callers': ['ghapi.core.GhApi'], 'callees': ['ghapi.core.list_branches', 'None.patch', 'None.len', 'None.str', 'ghapi.core.GhApi', 'ghapi.core.create_branch_empty', 'None.default_branch', 'None.NoneType', 'None.repos', 'None.has_pages', 'None.Exception'], 'co_dispatched': []}, {'rowid': 234, 'content': 'def _call_page(i, oper, args, kwargs, per_page):\n    return oper(*args, per_page=per_page, page=i, **kwargs)', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/page.py', 'uploaded_at': 1773452878.279083, 'name': '_call_page', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 65, 'end_lineno': 66, 'package': 'ghapi', 'version': '1.0.13', 'mod_name': 'ghapi.page._call_page'}, '_dist': 0.7832963466644287, '_rrf_score': 0.016129032258064516, '_src_id': 'env:234', 'node': 'ghapi.page._call_page', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/page.py', 'pagerank': 0.00018, 'in_degree': 1, 'out_degree': 0, 'callers': ['ghapi.page.pages'], 'callees': [], 'co_dispatched': []}, {'rowid': 1021, 'content': 'def test_is(a,b):\n    "`test` that `a is b`"\n    test(a,b,operator.is_, \'is\')', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/test.py', 'uploaded_at': 1776124140.6225286, 'name': 'test_is', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 79, 'end_lineno': 81, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.test.test_is'}, '_dist': 0.8132964372634888, '_rrf_score': 0.015873015873015872, '_src_id': 'env:1021', 'node': 'fastcore.test.test_is', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/test.py', 'pagerank': 3e-05, 'in_degree': 0, 'out_degree': 2, 'callers': [], 'callees': ['fastcore.test.test', 'None.operator'], 'co_dispatched': []}, {'rowid': 269, 'content': 'class PageUsage:\n    """Returned by :func:`analyze_pages`"""\n\n    page_size: int\n    "Size of pages in bytes.  All pages in the database are the same size."\n    pages_used: int\n    "Pages with content"\n    sequential_pages: int\n    "How many pages were sequential in the database file"\n    data_stored: int\n    "Bytes of SQL content stored"\n    cells: int\n    """Cells are what is `stored <https://www.sqlite.org/fileformat.html#b_tree_pages>`__\n    including sizing information, pointers to overflow etc"""\n    max_payload: int\n    "Largest cell size"\n    tables: list[str]\n    "Names of tables providing these statistics"\n    indices: list[str]\n    "Names of indices providing these statistics"', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/apsw/ext.py', 'uploaded_at': 1775879408.2738786, 'name': 'PageUsage', 'lang': '.py', 'type': 'ClassDef', 'lineno': 1279, 'end_lineno': 1298, 'package': 'apsw', 'version': '3.53.0.0', 'mod_name': 'apsw.ext.PageUsage'}, '_dist': 0.8182278275489807, '_rrf_score': 0.015625, '_src_id': 'env:269', 'callers': [], 'callees': [], 'co_dispatched': []}, {'rowid': 235, 'content': 'def pages(oper, n_pages, *args, n_workers=None, per_page=100, **kwargs):\n    "Get `n_pages` pages from `oper(*args,**kwargs)`"\n    return parallel(_call_page, range(1,n_pages+1), oper=oper, per_page=per_page, args=args, kwargs=kwargs,\n                    progress=False, n_workers=ifnone(n_workers,n_pages), threadpool=True)', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/page.py', 'uploaded_at': 1773452878.279083, 'name': 'pages', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 69, 'end_lineno': 72, 'package': 'ghapi', 'version': '1.0.13', 'mod_name': 'ghapi.page.pages'}, '_dist': 0.8282569646835327, '_rrf_score': 0.015384615384615385, '_src_id': 'env:235', 'node': 'ghapi.page.pages', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/page.py', 'pagerank': 0.00019, 'in_degree': 2, 'out_degree': 8, 'callers': ['ghapi.event.list_events_parallel', 'ghapi.event.description'], 'callees': ['None.int', 'None.parallel', 'ghapi.page._call_page', 'None.range', 'None.kwargs', 'None.ifnone', 'None.NoneType', 'None.args'], 'co_dispatched': []}, {'rowid': 8, 'content': "def pdf_texts(doc:PdfDocument, st=0, end=None) -> L:\n    'Extract plain text from each page.'\n    return L(range(st, ifnone(end, doc.page_count()))).map(doc.extract_text)", 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/litesearch/data.py', 'uploaded_at': 1776728074.0431254, 'name': 'pdf_texts', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 16, 'end_lineno': 18, 'package': 'litesearch', 'version': '0.0.22', 'mod_name': 'litesearch.data.pdf_texts'}, '_dist': 0.828606903553009, '_rrf_score': 0.015151515151515152, '_src_id': 'env:8', 'node': 'litesearch.data.pdf_texts', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/litesearch/data.py', 'pagerank': 0.00021, 'in_degree': 1, 'out_degree': 18, 'callers': ['litesearch.data.PdfDocument'], 'callees': ['None.int', 'None.L', 'None.extract_text', 'None.patch', 'None.range', 'None.PdfDocument', 'None.NoneType', 'None.page_count', 'None.ifnone', 'None.L', 'None.patch', 'None.ifnone', 'None.PdfDocument', 'None.range', 'None.int', 'None.extract_text', 'None.page_count', 'None.NoneType'], 'co_dispatched': []}, {'rowid': 12, 'content': "def pdf_tables(doc:PdfDocument, st=0, end=None) -> L:\n    'Extract structured tables (rows/cells/bbox) from each page.'\n    return L(range(st, ifnone(end, doc.page_count()))).map(lambda i: doc.extract_tables(i)).concat()", 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/litesearch/data.py', 'uploaded_at': 1776728074.0431254, 'name': 'pdf_tables', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 42, 'end_lineno': 44, 'package': 'litesearch', 'version': '0.0.22', 'mod_name': 'litesearch.data.pdf_tables'}, '_dist': 0.8292902708053589, '_rrf_score': 0.014925373134328358, '_src_id': 'env:12', 'node': 'litesearch.data.pdf_tables', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/litesearch/data.py', 'pagerank': 0.00021, 'in_degree': 1, 'out_degree': 16, 'callers': ['litesearch.data.PdfDocument'], 'callees': ['None.int', 'None.L', 'None.patch', 'None.range', 'None.PdfDocument', 'None.NoneType', 'None.page_count', 'None.ifnone', 'None.L', 'None.patch', 'None.ifnone', 'None.PdfDocument', 'None.range', 'None.int', 'None.page_count', 'None.NoneType'], 'co_dispatched': []}, {'rowid': 1016, 'content': 'def test_eq(a,b):\n    "`test` that `a==b`"\n    test(a,b,equals, cname=\'==\')', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/test.py', 'uploaded_at': 1776124140.6225286, 'name': 'test_eq', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 48, 'end_lineno': 50, 'package': 'fastcore', 'version': '1.12.39', 'mod_name': 'fastcore.test.test_eq'}, '_dist': 0.8305983543395996, '_rrf_score': 0.014705882352941176, '_src_id': 'env:1016', 'node': 'fastcore.test.test_eq', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/fastcore/test.py', 'pagerank': 5e-05, 'in_degree': 4, 'out_degree': 2, 'callers': ['fastcore.meta.test_sig', 'fastcore.test.test_eq_type', 'fastcore.test.test_shuffled', 'fastcore.test.test_stdout'], 'callees': ['fastcore.test.test', 'fastcore.imports.equals'], 'co_dispatched': []}, {'rowid': 149, 'content': 'def actions_group(title):\n    "Context manager to print the special `::group`/`::endgroup` lines for `title`"\n    print(f"::group::{title}")\n    yield\n    print(f"::endgroup::")', 'metadata': {'path': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/actions.py', 'uploaded_at': 1773452878.239776, 'name': 'actions_group', 'lang': '.py', 'type': 'FunctionDef', 'lineno': 142, 'end_lineno': 146, 'package': 'ghapi', 'version': '1.0.13', 'mod_name': 'ghapi.actions.actions_group'}, '_dist': 0.8310702443122864, '_rrf_score': 0.014492753623188406, '_src_id': 'env:149', 'node': 'ghapi.actions.actions_group', 'flavor': 'function', 'file': '/Users/71293/code/personal/orgs/karma/.venv/lib/python3.13/site-packages/ghapi/actions.py', 'pagerank': 0.00016, 'in_degree': 0, 'out_degree': 2, 'callers': [], 'callees': ['None.contextmanager', 'None.print'], 'co_dispatched': []}]
