SafePDF API is a self-hosted API that allows you to manage your important PDF documents in a local PocketBase database collection. You can perform CRUD (Create, Read, Update, Delete) operations on your PDF collection, making it easy to store, retrieve, and manage your documents.
- List all PDFs: Retrieve a list of all PDFs stored in your PocketBase collection.
- Get specific PDF: Retrieve a specific PDF by its title or ID.
- Get PDFs by author: Retrieve a list of all PDFs by a specific author.
- Upload PDF: Upload a new PDF by selecting a file from your local machine or by providing a URL.
- Re-upload PDF: Update an existing PDF by re-uploading it.
- Delete PDF: Delete a PDF from your collection by its title or ID.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.8+
- PocketBase
- An active PocketBase instance.
- A PocketBase collection with the following fields:
title(text)description(text)author(text)pdf(file)
- Clone the repository:
git clone https://github.com/CoderRony955/safepdf-api.git
Then Navigate to the cloned directory.
-
Install the dependencies:
pip install -r requirements.txt
-
Rename
.env.exampleto.safepdfapi.envfile in the root directory of the project and add the following environment variables:POCKETBASE_URL="<your-pocketbase-url>" COLLECTION="<your-collection-name>" POCKETBASE_EMAIL="<your-pocketbase-admin-email>" POCKETBASE_PASS="<your-pocketbase-admin-password>"
To run the API, execute the following command in the root directory of the project:
uvicorn main:app --reloadThe API will be available at http://localhost:8000. You can access the API documentation at http://localhost:8000/docs.
Leveraging services like ngrok or cloudflared allows you to securely access and manage your PDF documents from any remote location, enabling seamless interaction with your self-hosted PocketBase database over the internet.
If you want to access your SafePDF API from a remote location, you can use services like ngrok or cloudflared to expose your local server to the internet.
-
Install ngrok: Follow the instructions on the ngrok website to download and install ngrok.
-
Start your local server: Make sure your SafePDF API is running on
localhost:8000. -
Expose your local server: Open a new terminal window and run the following command:
ngrok http 8000
ngrok will generate a public URL that you can use to access your API from anywhere.
-
Install cloudflared: Follow the instructions on the Cloudflare Tunnel documentation to install
cloudflared. -
Start your local server: Make sure your SafePDF API is running on
localhost:8000. -
Expose your local server: Open a new terminal window and run the following command:
cloudflared tunnel --url http://localhost:8000
cloudflaredwill generate a public URL that you can use to access your API from anywhere.
Here is a list of the available API endpoints:
GET /: Get a list of all PDFs.GET /pdftitle/{title}: Get a specific PDF by title.GET /pdfid/{id}: Get a specific PDF by ID.GET /pdfauthor/{author}: Get a list of all PDFs by a specific author.POST /uploadbyselecting: Upload a new PDF by selecting a file.POST /uploadbyurl/{url}: Upload a new PDF from a URL.PUT /reuploadbytitle/{title}: Re-upload (update) a PDF by title.PUT /reuploadbyid/{id}: Re-upload (update) a PDF by ID.DELETE /deletebytitle/{title}: Delete a PDF by title.DELETE /deletebyid/{id}: Delete a PDF by ID.
For detailed information about each endpoint, please refer to the API documentation at http://localhost:8000/docs.