Skip to content

Commit c19cdda

Browse files
committed
Jupyter REST API project
1 parent fb8940b commit c19cdda

12 files changed

+463
-1
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.devcontainer/
2+
heroku-push.sh
3+
Pipfile.lock
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]

Dockerfile.web

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Base Image
2+
FROM python:3.6-slim
3+
4+
# COPY ./app /app
5+
6+
# create and set working directory
7+
RUN mkdir /app
8+
WORKDIR /app
9+
10+
# Add current directory code to working directory
11+
ADD . /app/
12+
13+
# set default environment variables
14+
ENV PYTHONUNBUFFERED 1
15+
ENV LANG C.UTF-8
16+
ENV DEBIAN_FRONTEND=noninteractive
17+
18+
# set project environment variables
19+
# grab these via the Python os.environ
20+
# these are 100% optional here
21+
# $PORT is set by Heroku
22+
ENV PORT=8888
23+
24+
# Install system dependencies with OpenCV
25+
RUN apt-get update && apt-get install -y --no-install-recommends \
26+
tzdata \
27+
python3-setuptools \
28+
python3-pip \
29+
python3-dev \
30+
python3-venv \
31+
git \
32+
&& \
33+
apt-get clean && \
34+
rm -rf /var/lib/apt/lists/*
35+
36+
37+
# install environment dependencies
38+
RUN pip3 install --upgrade pip
39+
RUN pip3 install pipenv
40+
41+
# Install project dependencies
42+
RUN pipenv install --skip-lock --system --dev
43+
44+
# Expose is NOT supported by Heroku
45+
# EXPOSE 8888
46+
CMD uvicorn src.server:app --host 0.0.0.0 --port ${PORT}

Pipfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
jupyter = "*"
10+
fastapi = "*"
11+
nbconvert = "*"
12+
uvicorn = "*"
13+
pandas = "*"
14+
requests = "*"
15+
requests-html = "*"
16+
nbdev = "*"
17+
18+
[requires]
19+
python_version = "3.6"

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: uvicorn src.server:app --host 0.0.0.0 --port $PORT

README.md

+76-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,77 @@
1-
# Jupter-Notebook-REST-API
1+
# Jupter Notebook REST API
22
Run your jupyter notebooks as a REST API endpoint. This isn't a jupyter server but rather just a way to run your notebooks as a REST API Endpoint.
3+
4+
5+
## Running locally
6+
7+
#### Clone project
8+
```
9+
mkdir rest-project
10+
cd rest-project
11+
git clone https://github.com/Invictify/Jupter-Notebook-REST-API .
12+
```
13+
14+
#### Install via Pipenv
15+
```
16+
pipenv install
17+
pipenv shell
18+
```
19+
> You can also use `pip install -r requirements.txt`
20+
21+
22+
### Add your notebook(s) to "src/notebooks"
23+
There's an example notebook already in there called `scrape.ipynb`.
24+
25+
26+
### Run locally
27+
28+
```
29+
pipenv run uvicorn src.server:app --reload
30+
```
31+
You can also do:
32+
33+
```
34+
chmod +x run.sh
35+
./run.sh
36+
```
37+
38+
## Trigger a notebook.
39+
With the server running, trigger notebook (relative path) like `notebooks/scrape.ipynb`
40+
41+
```python
42+
import requests
43+
r = requests.post("http://localhost:8000/trigger/notebooks/scrape.ipynb")
44+
print(r.json())
45+
```
46+
47+
48+
## Deployment
49+
50+
#### Create Heroku app
51+
You'll only have to do this 1 time.
52+
```
53+
heroku apps:create
54+
```
55+
56+
57+
### Using Git
58+
```
59+
git init
60+
git add --all
61+
git commit -m "Project commit"
62+
git push heroku master
63+
```
64+
65+
### Using Docker
66+
67+
#### Login to Heroku Container Registry
68+
```
69+
heroku container:login
70+
```
71+
72+
#### Build & Push to Heroku
73+
```
74+
docker build -t -f Dockerfile.web .
75+
heroku container:push web --recursive
76+
heroku container:release web
77+
```

jupyter-api.code-workspace

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"python.pythonPath": "/Users/jmitch/.local/share/virtualenvs/jupyter-api-ozsm8BnE/bin/python"
9+
}
10+
}

requirements.txt

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
appdirs==1.4.3
2+
appnope==0.1.0
3+
attrs==19.3.0
4+
backcall==0.1.0
5+
beautifulsoup4==4.8.2
6+
bleach==3.1.4
7+
bs4==0.0.1
8+
certifi==2019.11.28
9+
chardet==3.0.4
10+
click==7.1.1
11+
cssselect==1.1.0
12+
dataclasses==0.7
13+
decorator==4.4.2
14+
defusedxml==0.6.0
15+
entrypoints==0.3
16+
fake-useragent==0.1.11
17+
fastapi==0.53.2
18+
h11==0.9.0
19+
httptools==0.1.1
20+
idna==2.9
21+
importlib-metadata==1.6.0
22+
ipykernel==5.2.0
23+
ipython==7.13.0
24+
ipython-genutils==0.2.0
25+
ipywidgets==7.5.1
26+
jedi==0.16.0
27+
Jinja2==2.11.1
28+
jsonschema==3.2.0
29+
jupyter==1.0.0
30+
jupyter-client==6.1.2
31+
jupyter-console==6.1.0
32+
jupyter-core==4.6.3
33+
lxml==4.5.0
34+
MarkupSafe==1.1.1
35+
mistune==0.8.4
36+
nbconvert==5.6.1
37+
nbformat==5.0.4
38+
notebook==6.0.3
39+
numpy==1.18.2
40+
pandas==1.0.3
41+
pandocfilters==1.4.2
42+
parse==1.15.0
43+
parso==0.6.2
44+
pexpect==4.8.0
45+
pickleshare==0.7.5
46+
prometheus-client==0.7.1
47+
prompt-toolkit==3.0.5
48+
ptyprocess==0.6.0
49+
pydantic==1.4
50+
pyee==7.0.1
51+
Pygments==2.6.1
52+
pyppeteer==0.0.25
53+
pyquery==1.4.1
54+
pyrsistent==0.16.0
55+
python-dateutil==2.8.1
56+
pytz==2019.3
57+
pyzmq==19.0.0
58+
qtconsole==4.7.2
59+
QtPy==1.9.0
60+
requests==2.23.0
61+
requests-html==0.10.0
62+
selenium==3.141.0
63+
Send2Trash==1.5.0
64+
six==1.14.0
65+
soupsieve==2.0
66+
starlette==0.13.2
67+
terminado==0.8.3
68+
testpath==0.4.4
69+
tornado==6.0.4
70+
tqdm==4.44.1
71+
traitlets==4.3.3
72+
urllib3==1.25.8
73+
uvicorn==0.11.3
74+
uvloop==0.14.0
75+
w3lib==1.21.0
76+
wcwidth==0.1.9
77+
webencodings==0.5.1
78+
websockets==8.1
79+
widgetsnbextension==3.5.1
80+
zipp==3.1.0

run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uvicorn src.server:app --reload

src/data/2020.csv

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Rank,Release Group,Worldwide,Domestic,%,Foreign,%
2+
1,Bad Boys for Life,"$425,514,702","$204,417,855",48%,"$221,096,847",52%
3+
2,Sonic the Hedgehog,"$306,766,470","$146,066,470",47.6%,"$160,700,000",52.4%
4+
3,Dolittle,"$227,908,130","$77,047,065",33.8%,"$150,861,065",66.2%
5+
4,Birds of Prey: And the Fantabulous Emancipation of One Harley Quinn,"$201,858,461","$84,158,461",41.7%,"$117,700,000",58.3%
6+
5,The Invisible Man,"$124,558,377","$64,914,050",52.1%,"$59,644,327",47.9%
7+
6,The Gentlemen,"$117,758,649","$36,296,853",30.8%,"$81,461,796",69.2%
8+
7,The Call of the Wild,"$107,604,626","$62,342,368",57.9%,"$45,262,258",42.1%
9+
8,The Grudge,"$49,511,319","$21,221,803",42.9%,"$28,289,516",57.1%
10+
9,Fantasy Island,"$48,607,556","$26,441,782",54.4%,"$22,165,774",45.6%
11+
10,Underwater,"$40,882,928","$17,291,078",42.3%,"$23,591,850",57.7%
12+
11,Like a Boss,"$29,753,143","$22,169,514",74.5%,"$7,583,629",25.5%
13+
12,Bloodshot,"$29,749,454","$10,021,787",33.7%,"$19,727,667",66.3%
14+
13,Emma.,"$25,155,355","$10,055,355",40%,"$15,100,000",60%
15+
14,Gretel & Hansel,"$21,984,429","$15,347,654",69.8%,"$6,636,775",30.2%
16+
15,Brahms: The Boy II,"$20,311,536","$12,611,536",62.1%,"$7,700,000",37.9%
17+
16,The Turning,"$18,474,062","$15,472,775",83.8%,"$3,001,287",16.2%
18+
17,The Way Back,"$14,690,514","$13,590,514",92.5%,"$1,100,000",7.5%
19+
18,La Belle Époque,"$14,298,084",-,-,"$14,298,084",100%
20+
19,I Still Believe,"$10,482,561","$9,868,521",94.1%,"$614,040",5.9%
21+
20,The Hunt,"$6,512,500","$5,812,500",89.3%,"$700,000",10.7%
22+
21,Las Pildoras De Mi Novio,"$6,292,780","$2,971,116",47.2%,"$3,321,664",52.8%
23+
22,The Rhythm Section,"$5,989,583","$5,437,971",90.8%,"$551,612",9.2%
24+
23,My Spy,"$4,405,156",-,-,"$4,405,156",100%
25+
24,The Last Full Measure,"$3,006,059","$2,949,212",98.1%,"$56,847",1.9%
26+
25,The Lodge,"$2,679,438","$1,666,564",62.2%,"$1,012,874",37.8%
27+
26,Trolls World Tour,"$1,758,185",-,-,"$1,758,185",100%
28+
27,Blind Eyes Opened,"$234,505","$234,505",100%,-,-
29+
28,Burden,"$139,270","$139,270",100%,-,-
30+
29,"14 Days, 12 Nights","$122,806","$122,530",99.8%,$276,0.2%
31+
30,First Cow,"$101,068","$101,068",100%,-,-
32+
31,Run,"$4,052",-,-,"$4,052",100%
33+
32,Mulan,$874,-,-,$874,100%
34+
33,A Quiet Place Part II,$159,-,-,$159,100%

0 commit comments

Comments
 (0)