Metadata-Version: 2.5
Name: langchain-openalex
Version: 0.1.0
Summary: LangChain tools and retriever for OpenAlex, the free index of the world's scholarly research
Project-URL: Homepage, https://openalex.org
Project-URL: Repository, https://github.com/ourresearch/langchain-openalex
Project-URL: Documentation, https://help.openalex.org/llms.txt
Project-URL: Issues, https://github.com/ourresearch/langchain-openalex/issues
Author-email: OpenAlex <team@openalex.org>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,citations,langchain,openalex,papers,research,scholarly
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering
Requires-Python: <4.0,>=3.10
Requires-Dist: httpx<1.0.0,>=0.25.0
Requires-Dist: langchain-core<2.0.0,>=0.3.15
Description-Content-Type: text/markdown

# langchain-openalex

LangChain tools and a retriever for [OpenAlex](https://openalex.org), the free and open index of the
world's scholarly research: 250M+ papers, books, datasets and preprints across every field, with
authors, institutions, journals and citations. Maintained by the OpenAlex team.

## Install

```bash
pip install -U langchain-openalex
```

It works without a key. Requests without a key share a small free daily budget per IP address; a
free API key from [openalex.org/settings/api](https://openalex.org/settings/api) gives you your own:

```bash
export OPENALEX_API_KEY="your-key"
```

## Tools

```python
from langchain_openalex import OpenAlexGetWork, OpenAlexSearch

search = OpenAlexSearch(max_results=5)
search.invoke({"query": "kelp forest decline", "from_year": 2020, "open_access_only": True})

lookup = OpenAlexGetWork()
lookup.invoke({"identifier": "10.1038/s41586-021-03819-2"})
```

| Tool | What it does |
|---|---|
| `OpenAlexSearch` (`openalex_search`) | Keyword search over titles, abstracts and full text, with optional year range, open-access, work-type filters and sort (relevance, most cited, newest). |
| `OpenAlexGetWork` (`openalex_get_work`) | One work by DOI, OpenAlex ID (`W...`), `pmid:` or `pmcid:`. Free. |

Each work comes back as a flat record: `openalex_id`, `doi`, `title`, `publication_year`,
`publication_date`, `type`, `authors`, `source` (journal or repository), `cited_by_count`,
`is_open_access`, `open_access_url` and `abstract`.

With an agent:

```python
from langchain.agents import create_agent

agent = create_agent("anthropic:claude-sonnet-5-5", tools=[search, lookup])
agent.invoke(
    {"messages": [("user", "What are the most cited recent papers on kelp forest decline?")]}
)
```

## Retriever

```python
from langchain_openalex import OpenAlexRetriever

retriever = OpenAlexRetriever(k=5, from_year=2020)
docs = retriever.invoke("microplastics in drinking water")
# page_content = title + abstract; metadata = the other fields above
```

## More

This package uses OpenAlex's search and lookup endpoints. OpenAlex can do much more (authors,
institutions, funders, citation graphs, grouping and counting); see the docs index for agents at
[help.openalex.org/llms.txt](https://help.openalex.org/llms.txt). OpenAlex data is CC0.

Issues and pull requests welcome.
