Skip to main content

Overleaf API and simple CLI

Project description

PyOverleaf

Unofficial Python API to access Overleaf.

Tasks

  • List projects
  • Download project as zip
  • List and download individual files/docs
  • Upload new files/docs
  • Delete files, create folders
  • Python CLI interface to access project files
  • Move, rename files
  • Create, delete, archive, rename projects
  • Access/update comments, perform live changes
  • Access/update profile details
  • Robust login

Getting started

Install the project by running:

pip install 'pyoverleaf[cli]'

Before using the API, make sure you are logged into overleaf in your default web browser. Currently only Google Chrome and Mozila Firefox are supported: https://github.com/richardpenman/browsercookie Test if everything is working by listing the projects:

pyoverleaf ls

Python API

The low-level Python API provides a way to access Overleaf projects from Python. The main entrypoint is the class pyoverleaf.Api

Accessing projects

import pyoverleaf

api = pyoverleaf.Api()

# Lists the projects
projects = api.get_projects()

# Download the project as a zip
project_id = projects[0].id
api.download_project(project_id, "project.zip")

Managing project files

import pyoverleaf

api = pyoverleaf.Api()
# Choose a project
project_id = projects[0].id

# Get project files
root_folder = api.project_get_files(project_id)

# Create new folder
new_folder = api.project_create_folder(project_id, root_folder.id, "new-folder")

# Upload new file to the newly created folder
file_bytes = open("test-image.jpg", "rb").read()
new_file = api.project_upload_file(project_id, new_folder.id, "file-name.jpg", file_bytes)

# Delete newly added folder containing the file
api.project_delete_entity(project_id, new_folder)

Higher-level Python IO API

The higher-level Python IO API allows users to access the project files in a pythonic way. The main entrypoint is the class pyoverleaf.ProjectIO

Here are some examples on how to use the API:

import pyoverleaf

api = pyoverleaf.Api()
# Choose a project
project_id = projects[0].id

# Get project IO API
io = pyoverleaf.ProjectIO(api, project_id)

# Check if a path exists
exists = io.exists("path/to/a/file/or/folder")

# Create a directory
io.mkdir("path/to/new/directory", parents=True, exist_ok=True)

# Listing a directory
for entity in io.listdir("path/to/a/directory"):
    print(entity.name)

# Reading a file
with io.open("path/to/a/file", "r") as f:
    print(f.read())

# Creating a new file
with io.open("path/to/a/new/file", "w+") as f:
    f.write("new content")

Using the CLI

The CLI provides a way to access Overleaf from the shell. To get started, run pyoverleaf --help to list available commands and their arguments.

Listing projects and files

# Listing projects
pyoverleaf ls

# Listing project files
pyoverleaf ls project-name

# Listing project files in a folder
pyoverleaf ls project-name/path/to/files

Downloading existing projects

pyoverleaf download-project project-name output.zip

Creating and deleting directories

# Creating a new directory (including parents)
pyoverleaf mkdir -p project-name/path/to/new/directory

# Deleting
pyoverleaf rm project-name/path/to/new/directory

Reading and writing files

# Writing to a file
echo "new content" | pyoverleaf write project-name/path/to/file.txt

# Uploading an image
cat image.jpg | pyoverleaf write project-name/path/to/image.jpg

# Reading a file
pyoverleaf read project-name/path/to/file.txt

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

pyoverleaf-0.1.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

pyoverleaf-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyoverleaf-0.1.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyoverleaf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 680b8dfd012ff70da40c104804a6f028df96fa1a48f1fbfda50ad48a347fb5c2
MD5 503cbdb393dde02a085cc203a46aa099
BLAKE2b-256 4e8d0a0e39549369cb90c5d15465a9a8949dbb2089d53d890de2afb080f0a9c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoverleaf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pyoverleaf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28f53311a3fb6b534d4c83442cb28c3876b950c888490dc91e09a0d06e9f9ee0
MD5 c142055c6c8cc6ae153d4c3de5dbf6a8
BLAKE2b-256 87961d788c69401126bfe879dcb1c29a1c3a45da83564fce497cbdedee1bbce3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page