Skip to main content

Endoc SDK: A note-taking app SDK powered by LLMs

Project description

Endoc SDK Logo

Powered by Endoc

Endoc SDK

Endoc SDK is a Python library that provides powerful tools for advanced paper search, summarization, and note management using a GraphQL API. It leverages Pydantic for robust data validation and modeling, so that all responses are returned as easy‐to‐use Python objects. In addition, Endoc SDK offers an extensibility mechanism to allow you to create custom composite services without modifying the core code.

Features

  • Document Search: Search and filter papers using ranking variables and keywords.
  • Summarize Paper: Generate summaries for individual papers.
  • Paginated Search: Retrieve paginated search results.
  • Single Paper Search: Get detailed information about a single paper.
  • Note Library: Retrieve papers associated with a note.
  • Custom Services: Easily extend the client with your own functions.

Installation

Install Endoc SDK via pip:

pip install endoc

Setup

  1. Obtain Your API Key:

    • Visit https://endoc.ethz.ch and sign up using your Switch Edu-ID credentials.
    • After logging in, click on the Account option in the side panel.
    • Under the Developer API section, click Generate to create a new API key.
    • Copy the generated API key for later use.
  2. Create a .env File:

    • In your project's root directory, create a file named .env.
    • Add your API key to the file using the following format:
      API_KEY=your_api_key_here
      
  3. Load Environment Variables:

    • Install python-dotenv if you haven't already:
      pip install python-dotenv
      
    • In your Python script, load the environment variables at the very start:
      from dotenv import load_dotenv
      load_dotenv()
      
  4. Instantiate the Endoc client

    • In your Python script, instantiate a new instance of the EndocClient:
     client = EndocClient(api_key)
    

Basic Usage

1) Document Search

To search for papers, call the document_search method. This returns a DocumentSearchData object.

doc_search_result = client.document_search(
    ranking_variable="BERT",
    keywords=["AvailableField:Content.Fullbody_Parsed"]
)

# Accessing properties:
print(doc_search_result.status)
print(doc_search_result.response.search_stats.nMatchingDocuments)
print(doc_search_result.response.paper_list[0].id_value)

2) Summarize Paper

Call the summarize method with a paper ID to get a summary. The result is a SummarizationResponseData object.

summarize_result = client.summarize("221802394")
# Example usage:
print(summarize_result.status)
# You can further inspect summarize_result.response for detailed summary items.

3) Paginated Search

Use the paginated_search method to retrieve paginated results. Prepare a list of paper metadata as input.

example_paper = {
    "collection": "S2AG",
    "id_field": "id_int",
    "id_type": "int",
    "id_value": "221802394"
}
paper_list = [example_paper]
paginated_result = client.paginated_search(paper_list=paper_list)
# Example usage:
print(paginated_result.status)

4) Single Paper Search

To fetch detailed information for a single paper, use the single_paper method. This returns a SinglePaperData object.

single_paper_result = client.single_paper("221802394")
# Example usage:
print(single_paper_result.response.Title)

5) Get Note Library

Retrieve papers related to a note by calling the get_note_library method. This returns a GetNoteLibraryResponse object.

note_library_result = client.get_note_library("679a1e2e5b25cf001a7c7157")
if note_library_result.response:
    print(note_library_result.response[0].id_value)

Extending the Client with Custom Services

Endoc SDK allows you to add your own composite services without modifying the core code. You have two options:

Option 1: Using the register_service Decorator

Endoc SDK re-exports the register_service decorator, so you can define custom methods that become part of the client interface. For example:

from endoc import register_service

@register_service("combined_search")
def combined_search(self, paper_list, id_value):
    paginated = self.paginated_search(paper_list, keywords=["example"])
    single = self.single_paper(id_value)
    return {"paginated": paginated, "single": single}

# Now call the custom service:
result = client.combined_search(paper_list, "221802394")
print("Combined Search Result:", result)

Option 2: Using the register_service Method

Alternatively, you can register a custom service function directly on the client instance:

def my_custom_service(paper_list, id_value):
    paginated = client.paginated_search(paper_list, keywords=["custom"])
    single = client.single_paper(id_value)
    return {"paginated": paginated, "single": single}

client.register_service("my_custom_service", my_custom_service)

# Now call the custom service:
result = client.my_custom_service(paper_list, "221802394")
print("My Custom Service Result:", result)

Package Structure

The package is organized as follows:

endoc/
├── __init__.py            # Re-exports EndocClient and register_service
├── client.py              # Manages the GraphQL API connection
├── endoc_client.py        # Main client aggregating all services
├── decorators.py          # Provides the register_service decorator
├── queries/               # Contains GraphQL query definitions:
│   ├── document_search_query.py
│   ├── get_note_library_query.py
│   ├── paginated_search_query.py
│   ├── single_paper_query.py
│   └── summarize_paper_query.py
├── models/                # Contains all Pydantic models for responses:
│   ├── document_search.py
│   ├── note_library.py
│   ├── paginated_search.py
│   ├── single_paper.py
│   └── summarization.py
└── services/              # Contains service classes that wrap the queries:
    ├── document_search.py
    ├── get_note_library.py
    ├── paginated_search.py
    ├── single_paper_search.py
    └── summarization.py

Environment Variables

The SDK expects your API key as the environment variable API_KEY. Use a .env file and python-dotenv to load the variable:

from dotenv import load_dotenv
load_dotenv()

Contributing

Contributions are welcome! Please open issues or submit pull requests on the GitHub repository. Ensure that any contributions adhere to the existing code style and include tests where applicable.

License

This project is licensed under the MIT license.

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

endoc-1.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

endoc-1.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file endoc-1.0.0.tar.gz.

File metadata

  • Download URL: endoc-1.0.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.3

File hashes

Hashes for endoc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 26952c3897a2f63c21ab3c879a025995b11b206994df12e15687284085bbd2b2
MD5 c1720f1dcf2bdd22fa60b42c10de9d82
BLAKE2b-256 5a457500c0c18099cc68688aa8e8bb66a3d511988eae924949a912571730c614

See more details on using hashes here.

File details

Details for the file endoc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: endoc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.3

File hashes

Hashes for endoc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 625d00b3ec6cdd83ab3c9dbe6bd9abb63eaf2d30fcfc26d3a454fbd0823706ad
MD5 6007162eb4c56489377b877c735add49
BLAKE2b-256 2223b8d940375e1371f263131634bb3162734a3b43da0b8a0e190c750dc29988

See more details on using hashes here.

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