Skip to main content

Python SDK and CLI for ShareBib

Project description

ShareBib Python SDK and CLI

Python SDK and command-line interface for interacting with the ShareBib API.

Installation

Install from PyPI

pip install sharebib

This installs:

  • the Python package: sharebib
  • the preferred CLI command: sharebib
  • the compatibility CLI alias: sharebib-cli

Install the latest unreleased version from GitHub

pip install "git+https://github.com/visualdust/share-bib.git#subdirectory=sdk"

Local development

cd sdk
pip install -e .

Authentication

  1. Log in to your ShareBib instance
  2. Go to Settings
  3. In SDK API Keys, click Create API Key
  4. Copy the generated key (starts with pc_)

API Key Management

Configuration

Supported configuration sources, highest priority first:

  1. CLI flags / SDK constructor arguments
  2. Environment variables
  3. Project config: .sharebib/config.json
  4. User config: ~/.sharebib/config.json

Environment variables

export SHAREBIB_API_KEY="pc_your_api_key_here"
export SHAREBIB_BASE_URL="http://localhost:11550"
export SHAREBIB_TIMEOUT="30"

SHAREBIB_BASE_URL should be the application root URL. Do not append /api.

Config file example

{
  "api_key": "pc_your_api_key_here",
  "base_url": "http://localhost:11550",
  "timeout": 30
}

CLI Quick Start

Verify auth

sharebib auth info

sharebib is the preferred CLI name. sharebib-cli remains available as a compatibility alias. You can also run the CLI as python -m sharebib.

List collections

sharebib collections list

Search users for sharing

sharebib users search --q "gavin"

Create a collection

sharebib collections create \
  --title "My Research Papers" \
  --description "Papers I'm reading" \
  --visibility private \
  --tag machine-learning \
  --tag nlp

Add a paper

sharebib papers add \
  --collection-id "your-collection-id" \
  --title "Attention Is All You Need" \
  --author "Ashish Vaswani" \
  --author "Noam Shazeer" \
  --venue "NeurIPS" \
  --year 2017 \
  --arxiv-id "1706.03762" \
  --url-arxiv "https://arxiv.org/abs/1706.03762" \
  --url-pdf "https://arxiv.org/pdf/1706.03762.pdf" \
  --tag transformers \
  --tag attention

List papers in a collection

sharebib papers list --collection-id "your-collection-id"

Inspect a paper

sharebib papers info --id "paper-id"

Remove a paper from a collection

sharebib papers remove --collection-id "your-collection-id" --id "paper-id"

Search accessible papers

sharebib papers search --q "transformer" --limit 10

Manage collection permissions

sharebib collections permissions list --id "your-collection-id"
sharebib collections permissions add --id "your-collection-id" --user-id "user-id" --permission edit
sharebib collections permissions remove --id "your-collection-id" --user-id "user-id"

Export BibTeX

sharebib collections export-bibtex --id "your-collection-id" --output ./papers.bib

SDK Quick Start

from sharebib import ShareBibClient

client = ShareBibClient(
    base_url="http://localhost:11550",
    api_key="pc_your_api_key_here",
)

me = client.get_current_user()
print(me.username)

collection = client.create_collection(
    title="My Research Papers",
    description="Papers I'm reading",
    visibility="private",
    tags=["machine-learning", "nlp"],
)
print(f"Created collection: {collection.title} ({collection.id})")

paper = client.add_paper(
    collection_id=collection.id,
    title="Attention Is All You Need",
    authors=["Vaswani et al."],
    venue="NeurIPS",
    year=2017,
    arxiv_id="1706.03762",
    url_arxiv="https://arxiv.org/abs/1706.03762",
    url_pdf="https://arxiv.org/pdf/1706.03762.pdf",
    tags=["transformers", "attention"],
)
print(f"Added paper: {paper.title}")

for item in client.list_papers(collection.id):
    print(item.title)

for user in client.search_users("gavin"):
    print(user.username)

results = client.search_papers("transformer", limit=5)
print(len(results))

bibtex = client.export_collection_bibtex(collection.id)
print(bibtex[:120])

API Surface

Auth

  • get_current_user() / auth_info()

Users

  • search_users(q, limit=10)

Collections

  • list_collections()
  • create_collection(...)
  • get_collection(collection_id)
  • list_collection_permissions(collection_id)
  • set_collection_permission(collection_id, user_id=..., permission=...)
  • remove_collection_permission(collection_id, user_id)
  • export_collection_bibtex(collection_id)
  • delete_collection(collection_id)

Papers

  • add_paper(collection_id, title, ...)
  • list_papers(collection_id)
  • search_papers(q, limit=50, year=None, status=None)
  • get_paper(paper_id)
  • remove_paper(collection_id, paper_id)

Error Handling

from sharebib import ShareBibAPIError, ShareBibClient

client = ShareBibClient("http://localhost:11550", "pc_your_api_key_here")

try:
    client.get_collection("nonexistent-id")
except ShareBibAPIError as exc:
    print(exc)
    print(exc.status_code)

License

MIT

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

sharebib-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

sharebib-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sharebib-0.1.0.tar.gz.

File metadata

  • Download URL: sharebib-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sharebib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f6c712f86814538be1e441835d787a3c13eff1c55a65a59d1d3f97b240919c61
MD5 e5eeb33cbdd3d745c691a76c3903d8c2
BLAKE2b-256 4cccdbc869a369239b27741c8815b8479f8f984dcf1ef949cb3932102a999aba

See more details on using hashes here.

File details

Details for the file sharebib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sharebib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sharebib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a964f96fe9c55f42f1c9cbf417803d7740661315cd8bad3bcacd67122f2e3fe
MD5 d85a31fb74068e31d298f5016271800e
BLAKE2b-256 d49a58dc2afd0a31e5939199764963d8e222f9746171a7bd5a1eace2ab8a08f8

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