https://github.com/makramkd/pastebin
A simple implementation of a Pastebin-type service
https://github.com/makramkd/pastebin
async asyncio docker json pastebin postgresql python redis
Last synced: 2 months ago
JSON representation
A simple implementation of a Pastebin-type service
- Host: GitHub
- URL: https://github.com/makramkd/pastebin
- Owner: makramkd
- License: mit
- Created: 2020-03-30T18:52:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T03:57:28.000Z (over 2 years ago)
- Last Synced: 2024-11-12T12:48:42.893Z (6 months ago)
- Topics: async, asyncio, docker, json, pastebin, postgresql, python, redis
- Language: Python
- Homepage:
- Size: 49.8 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - makramkd/pastebin - A simple implementation of a Pastebin-type service (python)
README
# Pastebin
A simple implementation of a Pastebin-type service. If you're unfamiliar with what Pastebin is,
see [pastebin.com](https://pastebin.com/).This is mostly done for learning and fun. It isn't production ready!
# Architecture Diagram

# Building
You can build everything using [Docker](https://www.docker.com/).
To build the Pastebin image:
```bash
# Inside top level directory
docker build -t pastebin-dev -f Dockerfile .
```To build the database image:
```bash
# Inside the db/ directory
docker build -t pastebin-pg -f Dockerfile .
```Or, if you'd rather use `docker-compose`:
```bash
# Inside top level directory
docker-compose up --build
```For local development, you can do:
```bash
# Ensure python 3
pyenv local 3.6.3 # or whichever version you like (3.6+ only)
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```# Tests
Run unit tests via:
```bash
python setup.py test
```# API
The API is intentionally kept very simple.
## `GET /api/v1/pastes/`
Get the contents of a paste from the given shortlink. If the paste doesn't exist,
a 404 Not Found status code is returned. If the paste exists, it will be returned
in the following JSON body:```javascript
{
"paste_content": "hello world! this is my first paste and i'm loving it!"
}
```## `POST /api/v1/pastes`
Create a new paste. The request body must be JSON, with the following form:
```javascript
{
"paste_content": "string",
"time_to_live": 12345, // optional, time to live of the paste in seconds
}
```If a time to live isn't given the paste will never expire. Otherwise, the paste
will be set to expired - and will no longer be accessible - after the specified time
has passed.# Still To Do
* Implement paste expiry using Redis queues (DONE)
* Unit tests of async behavior
* Integration tests of system
* Add docstrings to API, classes, and functions