├── .editorconfig
├── .env.template
├── .github
├── actions
│ └── setup-poetry-env
│ │ └── action.yml
└── workflows
│ ├── main.yml
│ └── publish.yml
├── .gitignore
├── .pre-commit-config.yaml
├── Dockerfile
├── DockerfileCPU
├── LICENSE
├── Makefile
├── README.md
├── SETUP.md
├── data
└── .gitignore
├── docker-compose.yml
├── frontend
├── .dockerignore
├── .eslintrc.json
├── .gitignore
├── Dockerfile
├── README.md
├── app
│ ├── components
│ │ ├── GitHubButton.tsx
│ │ ├── GoogleAnalytics.tsx
│ │ ├── Header.tsx
│ │ ├── InfoBox.tsx
│ │ ├── ScatterPlot.tsx
│ │ ├── SearchResultsTable.tsx
│ │ ├── SupportButton.tsx
│ │ └── ToggleSwitch.tsx
│ ├── favicon.ico
│ ├── globals.css
│ ├── layout.tsx
│ ├── page.tsx
│ └── utils
│ │ └── search.ts
├── next.config.mjs
├── package-lock.json
├── package.json
├── postcss.config.mjs
├── public
│ ├── kofi.png
│ ├── next.svg
│ ├── pypi-light.svg
│ ├── pypi.svg
│ └── vercel.svg
├── tailwind.config.ts
└── tsconfig.json
├── package-lock.json
├── package.json
├── poetry.lock
├── pypi_bigquery.sql
├── pypi_scout
├── __init__.py
├── api
│ ├── data_loader.py
│ ├── main.py
│ └── models.py
├── config.py
├── data
│ ├── description_cleaner.py
│ └── raw_data_reader.py
├── embeddings
│ ├── embeddings_creator.py
│ └── simple_vector_database.py
├── scripts
│ ├── create_vector_embeddings.py
│ ├── download_raw_dataset.py
│ ├── process_raw_dataset.py
│ ├── setup.py
│ └── upload_processed_datasets.py
└── utils
│ ├── blob_io.py
│ ├── logging.py
│ └── score_calculator.py
├── pyproject.toml
├── requirements-cpu.txt
├── static
├── demo.gif
├── pypi-light.svg
└── pypi.svg
└── tests
└── embeddings
└── test_simple_vector_database.py
/.editorconfig:
--------------------------------------------------------------------------------
1 | max_line_length = 120
2 |
3 | [*.json]
4 | indent_style = space
5 | indent_size = 4
6 |
--------------------------------------------------------------------------------
/.env.template:
--------------------------------------------------------------------------------
1 | STORAGE_BACKEND=BLOB
2 | STORAGE_BACKEND_BLOB_ACCOUNT_NAME=
3 | STORAGE_BACKEND_BLOB_CONTAINER_NAME=
4 | STORAGE_BACKEND_BLOB_KEY=
5 |
--------------------------------------------------------------------------------
/.github/actions/setup-poetry-env/action.yml:
--------------------------------------------------------------------------------
1 | name: "setup-poetry-env"
2 | description: "Composite action to setup the Python and poetry environment."
3 |
4 | inputs:
5 | python-version:
6 | required: false
7 | description: "The python version to use"
8 | default: "3.11"
9 |
10 | runs:
11 | using: "composite"
12 | steps:
13 | - name: Set up python
14 | uses: actions/setup-python@v5
15 | with:
16 | python-version: ${{ inputs.python-version }}
17 |
18 | - name: Install Poetry
19 | uses: snok/install-poetry@v1
20 | with:
21 | virtualenvs-in-project: true
22 |
23 | - name: Load cached venv
24 | id: cached-poetry-dependencies
25 | uses: actions/cache@v4
26 | with:
27 | path: .venv
28 | key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}
29 |
30 | - name: Install dependencies
31 | if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
32 | run: poetry install --no-interaction
33 | shell: bash
34 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Main
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 | types: [opened, synchronize, reopened, ready_for_review]
9 |
10 | jobs:
11 | quality:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - name: Check out
15 | uses: actions/checkout@v4
16 |
17 | - uses: actions/cache@v4
18 | with:
19 | path: ~/.cache/pre-commit
20 | key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
21 |
22 | - name: Set up the environment
23 | uses: ./.github/actions/setup-poetry-env
24 |
25 | - name: Run checks
26 | run: make check
27 |
28 | tox:
29 | runs-on: ubuntu-latest
30 | strategy:
31 | matrix:
32 | python-version: ["3.9", "3.10", "3.11", "3.12"]
33 | fail-fast: false
34 | steps:
35 | - name: Check out
36 | uses: actions/checkout@v4
37 |
38 | - name: Set up python
39 | uses: actions/setup-python@v5
40 | with:
41 | python-version: ${{ matrix.python-version }}
42 |
43 | - name: Install Poetry
44 | uses: snok/install-poetry@v1
45 |
46 | - name: Load cached venv
47 | uses: actions/cache@v4
48 | with:
49 | path: .tox
50 | key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
51 |
52 | - name: Install tox
53 | run: |
54 | python -m pip install --upgrade pip
55 | python -m pip install tox tox-gh-actions
56 |
57 | - name: Test with tox
58 | run: tox
59 |
60 | - name: Upload coverage reports to Codecov with GitHub Action on Python 3.11
61 | uses: codecov/codecov-action@v4
62 | if: ${{ matrix.python-version == '3.11' }}
63 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Build and Push Docker Images
2 |
3 | on:
4 | workflow_dispatch:
5 |
6 | jobs:
7 | build-and-push-backend:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - name: Checkout repository
11 | uses: actions/checkout@v2
12 |
13 | - name: Set up Docker Buildx
14 | uses: docker/setup-buildx-action@v2
15 |
16 | - name: Login to Azure Container Registry
17 | uses: azure/docker-login@v1
18 | with:
19 | login-server: pypiscoutacr.azurecr.io
20 | username: ${{ secrets.ACR_USERNAME }}
21 | password: ${{ secrets.ACR_PASSWORD }}
22 |
23 | - name: Build and Push Backend Docker image
24 | uses: docker/build-push-action@v4
25 | with:
26 | context: .
27 | file: ./DockerfileCPU
28 | platforms: linux/amd64
29 | push: true
30 | tags: pypiscoutacr.azurecr.io/pypi-scout-backend:latest
31 |
32 | build-and-push-frontend:
33 | runs-on: ubuntu-latest
34 | steps:
35 | - name: Checkout repository
36 | uses: actions/checkout@v2
37 |
38 | - name: Set up Docker Buildx
39 | uses: docker/setup-buildx-action@v2
40 |
41 | - name: Login to Azure Container Registry
42 | uses: azure/docker-login@v1
43 | with:
44 | login-server: pypiscoutacr.azurecr.io
45 | username: ${{ secrets.ACR_USERNAME }}
46 | password: ${{ secrets.ACR_PASSWORD }}
47 |
48 | - name: Build and Push Frontend Docker image
49 | uses: docker/build-push-action@v4
50 | with:
51 | context: ./frontend
52 | file: ./frontend/Dockerfile
53 | platforms: linux/amd64
54 | push: true
55 | tags: pypiscoutacr.azurecr.io/pypi-scout-frontend:latest
56 | build-args: |
57 | NEXT_PUBLIC_API_URL=https://pypiscout.com/api
58 | NEXT_PUBLIC_GA_TRACKING_ID=${{ secrets.NEXT_PUBLIC_GA_TRACKING_ID }}
59 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | docs/source
2 |
3 | # From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
4 |
5 | # Byte-compiled / optimized / DLL files
6 | __pycache__/
7 | *.py[cod]
8 | *$py.class
9 |
10 | # C extensions
11 | *.so
12 |
13 | # Distribution / packaging
14 | .Python
15 | build/
16 | develop-eggs/
17 | dist/
18 | downloads/
19 | eggs/
20 | .eggs/
21 | lib/
22 | lib64/
23 | parts/
24 | sdist/
25 | var/
26 | wheels/
27 | share/python-wheels/
28 | *.egg-info/
29 | .installed.cfg
30 | *.egg
31 | MANIFEST
32 |
33 | # PyInstaller
34 | # Usually these files are written by a python script from a template
35 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
36 | *.manifest
37 | *.spec
38 |
39 | # Installer logs
40 | pip-log.txt
41 | pip-delete-this-directory.txt
42 |
43 | # Unit test / coverage reports
44 | htmlcov/
45 | .tox/
46 | .nox/
47 | .coverage
48 | .coverage.*
49 | .cache
50 | nosetests.xml
51 | coverage.xml
52 | *.cover
53 | *.py,cover
54 | .hypothesis/
55 | .pytest_cache/
56 | cover/
57 |
58 | # Translations
59 | *.mo
60 | *.pot
61 |
62 | # Django stuff:
63 | *.log
64 | local_settings.py
65 | db.sqlite3
66 | db.sqlite3-journal
67 |
68 | # Flask stuff:
69 | instance/
70 | .webassets-cache
71 |
72 | # Scrapy stuff:
73 | .scrapy
74 |
75 | # Sphinx documentation
76 | docs/_build/
77 |
78 | # PyBuilder
79 | .pybuilder/
80 | target/
81 |
82 | # Jupyter Notebook
83 | .ipynb_checkpoints
84 |
85 | # IPython
86 | profile_default/
87 | ipython_config.py
88 |
89 | # pyenv
90 | # For a library or package, you might want to ignore these files since the code is
91 | # intended to run in multiple environments; otherwise, check them in:
92 | # .python-version
93 |
94 | # pipenv
95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
98 | # install all needed dependencies.
99 | #Pipfile.lock
100 |
101 | # poetry
102 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103 | # This is especially recommended for binary packages to ensure reproducibility, and is more
104 | # commonly ignored for libraries.
105 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106 | #poetry.lock
107 |
108 | # pdm
109 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110 | #pdm.lock
111 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112 | # in version control.
113 | # https://pdm.fming.dev/#use-with-ide
114 | .pdm.toml
115 |
116 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117 | __pypackages__/
118 |
119 | # Celery stuff
120 | celerybeat-schedule
121 | celerybeat.pid
122 |
123 | # SageMath parsed files
124 | *.sage.py
125 |
126 | # Environments
127 | .env
128 | .venv
129 | env/
130 | venv/
131 | ENV/
132 | env.bak/
133 | venv.bak/
134 |
135 | # Spyder project settings
136 | .spyderproject
137 | .spyproject
138 |
139 | # Rope project settings
140 | .ropeproject
141 |
142 | # mkdocs documentation
143 | /site
144 |
145 | # mypy
146 | .mypy_cache/
147 | .dmypy.json
148 | dmypy.json
149 |
150 | # Pyre type checker
151 | .pyre/
152 |
153 | # pytype static type analyzer
154 | .pytype/
155 |
156 | # Cython debug symbols
157 | cython_debug/
158 |
159 | # Vscode config files
160 | .vscode/
161 |
162 | # PyCharm
163 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
164 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
165 | # and can be added to the global gitignore or merged into this file. For a more nuclear
166 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
167 | #.idea/
168 |
169 | .env
170 | .DS_Store
171 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: "v4.4.0"
4 | hooks:
5 | - id: check-case-conflict
6 | - id: check-merge-conflict
7 | - id: check-toml
8 | - id: check-yaml
9 | - id: end-of-file-fixer
10 | - id: trailing-whitespace
11 |
12 | - repo: https://github.com/astral-sh/ruff-pre-commit
13 | rev: "v0.1.6"
14 | hooks:
15 | - id: ruff
16 | args: [--exit-non-zero-on-fix]
17 | - id: ruff-format
18 |
19 | - repo: https://github.com/pre-commit/mirrors-prettier
20 | rev: "v3.0.3"
21 | hooks:
22 | - id: prettier
23 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1
2 |
3 | FROM python:3.10-slim-bookworm
4 |
5 | ENV POETRY_VERSION=1.6 \
6 | POETRY_VIRTUALENVS_CREATE=false
7 |
8 | # Install poetry and clean up
9 | RUN pip install "poetry==$POETRY_VERSION" && \
10 | rm -rf /root/.cache/pip
11 |
12 | # Set work directory
13 | WORKDIR /code
14 |
15 | # Copy only requirements to cache them in docker layer
16 | COPY poetry.lock pyproject.toml /code/
17 |
18 | # Install project dependencies and clean up
19 | RUN poetry install --no-interaction --no-ansi --no-root --no-dev && \
20 | rm -rf /root/.cache/pip
21 |
22 | # Copy Python code to the Docker image
23 | COPY pypi_scout /code/pypi_scout/
24 |
25 | # Make empty data directory
26 | RUN mkdir -p /code/data
27 |
28 | ENV PYTHONPATH=/code
29 |
30 | # Use the script as the entrypoint
31 | CMD ["uvicorn", "pypi_scout.api.main:app", "--host", "0.0.0.0", "--port", "8000"]
32 |
--------------------------------------------------------------------------------
/DockerfileCPU:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1
2 |
3 | # Use a slim Python image as the base
4 | FROM python:3.10-slim-bookworm
5 |
6 | # Set environment variables
7 | ENV PYTHONUNBUFFERED=1
8 |
9 | # Install system dependencies
10 | RUN apt-get update && apt-get install -y --no-install-recommends \
11 | build-essential \
12 | && apt-get clean && rm -rf /var/lib/apt/lists/*
13 |
14 | # Set working directory
15 | WORKDIR /code
16 |
17 | # Copy only requirements to cache them in docker layer
18 | COPY requirements-cpu.txt /code/requirements-cpu.txt
19 |
20 | # Install Python dependencies
21 | RUN pip install --no-cache-dir -r requirements-cpu.txt
22 |
23 | # Copy the rest of the application code
24 | COPY pypi_scout /code/pypi_scout/
25 |
26 | # Make empty data directory
27 | RUN mkdir -p /code/data
28 |
29 | ENV PYTHONPATH=/code
30 |
31 | # Use the script as the entrypoint
32 | CMD ["uvicorn", "pypi_scout.api.main:app", "--host", "0.0.0.0", "--port", "8000"]
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: install
2 | install: ## Install the poetry environment and install the pre-commit hooks
3 | @echo "🚀 Creating virtual environment using pyenv and poetry"
4 | @poetry install
5 | @ poetry run pre-commit install
6 | @poetry shell
7 |
8 | .PHONY: check
9 | check: ## Run code quality tools.
10 | @echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry check --lock"
11 | @poetry check --lock
12 | @echo "🚀 Linting code: Running pre-commit"
13 | @poetry run pre-commit run -a
14 | @echo "🚀 Checking for obsolete dependencies: Running deptry"
15 | @poetry run deptry .
16 |
17 | .PHONY: test
18 | test: ## Test the code with pytest
19 | @echo "🚀 Testing code: Running pytest"
20 | @poetry run pytest --cov --cov-config=pyproject.toml --cov-report=xml
21 |
22 | .PHONY: build
23 | build: ## Build wheel file using poetry
24 | @echo "🚀 Creating wheel file"
25 | @poetry build
26 |
27 | .PHONY: serve
28 | serve: ## Serve API with uvicorn in development mode
29 | @poetry run uvicorn pypi_scout.api.main:app --reload
30 |
31 | .PHONY: frontend
32 | frontend: ## Serve frontend in development mode
33 | @cd frontend; npm run dev
34 |
35 | .PHONY: help
36 | help:
37 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
38 |
39 | .DEFAULT_GOAL := help
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | ## What does this do?
11 |
12 | Finding the right Python package on [PyPI](https://pypi.org/) can be a bit difficult, since PyPI isn't really designed for discovering packages easily. For example, you can search for the word "plot" and get a list of hundreds of packages that contain the word "plot" in seemingly random order.
13 |
14 | Inspired by [this blog post](https://koaning.io/posts/search-boxes/) about finding arXiv articles using vector embeddings, I decided to build a small application that helps you find Python packages with a similar approach. For example, you can ask it "I want to make nice plots and visualizations", and it will provide you with a short list of packages that can help you with that.
15 |
16 | ## How does this work?
17 |
18 | The project works by collecting project summaries and descriptions for all packages on PyPI with more than 100 weekly downloads. These are then converted into vector representations using [Sentence Transformers](https://www.sbert.net/). When the user enters a query, it is converted into a vector representation, and the most similar package descriptions are fetched from the vector database. Additional weight is given to the amount of weekly downloads before presenting the results to the user in a dashboard.
19 |
20 | ## Stack
21 |
22 | The project uses the following technologies:
23 |
24 | 1. **[FastAPI](https://fastapi.tiangolo.com/)** for the API backend
25 | 2. **[NextJS](https://nextjs.org/) and [TailwindCSS](https://tailwindcss.com/)** for the frontend
26 | 3. **[Sentence Transformers](https://www.sbert.net/)** for vector embeddings
27 |
28 | ## Getting Started
29 |
30 | ### Build and Setup
31 |
32 | #### 1. (Optional) **Create a `.env` file**
33 |
34 | By default, all data will be stored on your local machine. It is also possible to store the data for the API on Azure Blob storage, and
35 | have the API read from there. To do so, create a `.env` file:
36 |
37 | ```sh
38 | cp .env.template .env
39 | ```
40 |
41 | and fill in the required fields.
42 |
43 | #### 2. **Run the Setup Script**
44 |
45 | The setup script will:
46 |
47 | - Download and process the PyPI dataset and store the results in the `data` directory.
48 | - Create vector embeddings for the PyPI dataset.
49 | - If the `STORAGE_BACKEND` environment variable is set to `BLOB`: Upload the datasets to blob storage.
50 |
51 | There are three methods to run the setup script, dependent on if you have a NVIDIA GPU and [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) installed. Please run the setup script using the method that is applicable for you:
52 |
53 | - [Option 1: Using Poetry](SETUP.md#option-1-using-poetry)
54 | - [Option 2: Using Docker with NVIDIA GPU and NVIDIA Container Toolkit](SETUP.md#option-2-using-docker-with-nvidia-gpu-and-nvidia-container-toolkit)
55 | - [Option 3: Using Docker without NVIDIA GPU and NVIDIA Container Toolkit](SETUP.md#option-3-using-docker-without-nvidia-gpu-and-nvidia-container-toolkit)
56 |
57 | > [!NOTE]
58 | > The dataset contains approximately 100.000 packages on PyPI with more than 100 weekly downloads. To speed up local development,
59 | > you can lower the amount of packages that is processed locally by lowering the value of `FRAC_DATA_TO_INCLUDE` in `pypi_scout/config.py`.
60 |
61 | #### 3. **Run the Application**
62 |
63 | Start the application using Docker Compose:
64 |
65 | ```sh
66 | docker-compose up
67 | ```
68 |
69 | After a short while, your application will be live at [http://localhost:3000](http://localhost:3000).
70 |
71 | ## Data
72 |
73 | The dataset for this project is created using the [PyPI dataset on Google BigQuery](https://console.cloud.google.com/marketplace/product/gcp-public-data-pypi/pypi?project=regal-net-412415). The SQL query used can be found in [pypi_bigquery.sql](./pypi_bigquery.sql). The resulting dataset is available as a CSV file on [Google Drive](https://drive.google.com/file/d/1huR7-VD3AieBRCcQyRX9MWbPLMb_czjq/view?usp=sharing).
74 |
--------------------------------------------------------------------------------
/SETUP.md:
--------------------------------------------------------------------------------
1 | # Running the Setup Script
2 |
3 | The setup script will:
4 |
5 | - Download and process the PyPI dataset and store the results in the `data` directory.
6 | - Create vector embeddings for the PyPI dataset.
7 | - If the `STORAGE_BACKEND` environment variable is set to `BLOB`: Upload the datasets to blob storage.
8 |
9 | There are three ways to run the setup script:
10 |
11 | ### Option 1: Using Poetry
12 |
13 | You can run the setup script using a virtual environment with Poetry. This method will automatically utilize your GPU for the vector embeddings if it is detected.
14 |
15 | 1. Install dependencies and set up the virtual environment:
16 |
17 | ```sh
18 | poetry install
19 | ```
20 |
21 | 2. Run the setup script:
22 |
23 | ```sh
24 | poetry run python pypi_scout/scripts/setup.py
25 | ```
26 |
27 | ### Option 2: Using Docker with NVIDIA GPU and NVIDIA Container Toolkit
28 |
29 | If you have an NVIDIA GPU and the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) installed, follow these steps:
30 |
31 | 1. Build the Docker image:
32 |
33 | ```sh
34 | docker build -t pypi-scout .
35 | ```
36 |
37 | 2. Run the setup script in a Docker container with GPU support:
38 |
39 | ```sh
40 | docker run --rm \
41 | --gpus all \
42 | --env-file .env \
43 | -v $(pwd)/data:/code/data \
44 | --entrypoint "/bin/bash" \
45 | pypi-scout \
46 | -c "python /code/pypi_scout/scripts/setup.py"
47 | ```
48 |
49 | ### Option 3: Using Docker without NVIDIA GPU and NVIDIA Container Toolkit
50 |
51 | If you do not have an NVIDIA GPU or the NVIDIA Container Toolkit installed, follow these steps:
52 |
53 | 1. Build the Docker image:
54 |
55 | ```sh
56 | docker build -f DockerfileCPU -t pypi-scout .
57 | ```
58 |
59 | 2. Run the setup script in a Docker container without GPU support:
60 |
61 | ```sh
62 | docker run --rm \
63 | --env-file .env \
64 | -v $(pwd)/data:/code/data \
65 | --entrypoint "/bin/bash" \
66 | pypi-scout \
67 | -c "python /code/pypi_scout/scripts/setup.py"
68 | ```
69 |
70 | ### Running the Application
71 |
72 | After setting up the dataset, start the application using Docker Compose:
73 |
74 | ```sh
75 | docker-compose up
76 | ```
77 |
78 | After a short while, your application will be live at [http://localhost:3000](http://localhost:3000).
79 |
--------------------------------------------------------------------------------
/data/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
5 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | services:
4 | backend:
5 | build:
6 | context: .
7 | dockerfile: Dockerfile
8 | ports:
9 | - "8000:8000"
10 | volumes:
11 | - ./data:/code/data
12 | env_file:
13 | - .env
14 |
15 | frontend:
16 | build:
17 | context: ./frontend
18 | dockerfile: Dockerfile
19 | args:
20 | NEXT_PUBLIC_API_URL: http://localhost:8000/api
21 | ports:
22 | - "3000:3000"
23 | depends_on:
24 | - backend
25 |
--------------------------------------------------------------------------------
/frontend/.dockerignore:
--------------------------------------------------------------------------------
1 | # .dockerignore
2 | node_modules
3 | .next
4 | .env
5 | .git
6 |
--------------------------------------------------------------------------------
/frontend/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "next/core-web-vitals"
3 | }
4 |
--------------------------------------------------------------------------------
/frontend/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | .yarn/install-state.gz
8 |
9 | # testing
10 | /coverage
11 |
12 | # next.js
13 | /.next/
14 | /out/
15 |
16 | # production
17 | /build
18 |
19 | # misc
20 | .DS_Store
21 | *.pem
22 |
23 | # debug
24 | npm-debug.log*
25 | yarn-debug.log*
26 | yarn-error.log*
27 |
28 | # local env files
29 | .env*.local
30 |
31 | # vercel
32 | .vercel
33 |
34 | # typescript
35 | *.tsbuildinfo
36 | next-env.d.ts
37 |
38 | .next
39 |
--------------------------------------------------------------------------------
/frontend/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use the official Node.js image as the base image
2 | FROM node:18-alpine
3 |
4 | # Set the working directory inside the container
5 | WORKDIR /app
6 |
7 | # Copy package.json and package-lock.json files to the container
8 | COPY package.json package-lock.json ./
9 |
10 | # Install dependencies
11 | RUN npm install
12 |
13 | # Copy the rest of the application code to the container
14 | COPY . .
15 |
16 | # Add build arguments to environment
17 | ARG NEXT_PUBLIC_API_URL
18 | ARG NEXT_PUBLIC_GA_TRACKING_ID
19 | ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
20 | ENV NEXT_PUBLIC_GA_TRACKING_ID=${NEXT_PUBLIC_GA_TRACKING_ID}
21 |
22 | # Build the Next.js application
23 | RUN npm run build
24 |
25 | # Expose the port on which the application will run
26 | EXPOSE 3000
27 |
28 | # Start the Next.js application
29 | CMD ["npm", "run", "start"]
30 |
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2 |
3 | ## Getting Started
4 |
5 | First, run the development server:
6 |
7 | ```bash
8 | npm run dev
9 | ```
10 |
11 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
12 |
13 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
14 |
15 | This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
16 |
17 | ## Learn More
18 |
19 | To learn more about Next.js, take a look at the following resources:
20 |
21 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
22 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
23 |
24 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
25 |
--------------------------------------------------------------------------------
/frontend/app/components/GitHubButton.tsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const GitHubButton: React.FC = () => {
4 | return (
5 |
11 |
20 | GitHub
21 |
22 | );
23 | };
24 |
25 | export default GitHubButton;
26 |
--------------------------------------------------------------------------------
/frontend/app/components/GoogleAnalytics.tsx:
--------------------------------------------------------------------------------
1 | // app/components/GoogleAnalytics.tsx
2 | "use client";
3 |
4 | import { useEffect } from "react";
5 |
6 | const GoogleAnalytics = () => {
7 | useEffect(() => {
8 | const trackingId = process.env.NEXT_PUBLIC_GA_TRACKING_ID;
9 | if (trackingId) {
10 | const script1 = document.createElement("script");
11 | script1.async = true;
12 | script1.src = `https://www.googletagmanager.com/gtag/js?id=${trackingId}`;
13 | document.head.appendChild(script1);
14 |
15 | const script2 = document.createElement("script");
16 | script2.innerHTML = `
17 | window.dataLayer = window.dataLayer || [];
18 | function gtag(){dataLayer.push(arguments);}
19 | gtag('js', new Date());
20 | gtag('config', '${trackingId}');
21 | `;
22 | document.head.appendChild(script2);
23 | }
24 | }, []);
25 |
26 | return null;
27 | };
28 |
29 | export default GoogleAnalytics;
30 |
--------------------------------------------------------------------------------
/frontend/app/components/Header.tsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react";
2 | import GitHubButton from "./GitHubButton";
3 | import SupportButton from "./SupportButton";
4 | import { FaBars, FaTimes } from "react-icons/fa";
5 |
6 | const Header: React.FC = () => {
7 | const [isMenuOpen, setIsMenuOpen] = useState(false);
8 |
9 | const toggleMenu = () => {
10 | setIsMenuOpen(!isMenuOpen);
11 | };
12 |
13 | return (
14 |
15 |
16 | This application allows you to search for Python packages on PyPI using
17 | natural language queries. For example, a query could be "a package
18 | that creates plots and beautiful visualizations".
19 |
20 |
21 |
22 | Once you click search, your query will be matched against the summary
23 | and the first part of the description of the ~100.000 most popular
24 | packages on PyPI, which includes all packages with at least ~100
25 | downloads per week. The results are then scored based on their
26 | similarity to the query and their number of weekly downloads, and the
27 | best results are displayed in the plot and table above.
28 |