Package Search Help

You can use boolean logic (e.g. AND/OR/NOT) for complex search queries. For more help and examples, see the search documentation.

Search by package name:
my-package (implicit)
name:my-package (explicit)

Search by package filename:
filename:my-package.ext 

Search by package tag:
tag:latest 

Search by package version:
version:1.0.0  prerelease:true (prereleases)
prerelease:false (no prereleases)

Search by package architecture:
architecture:x86_64 

Search by package distribution:
distribution:el 

Search by package license:
license:MIT 

Search by package format:
format:deb 

Search by package status:
status:in_progress 

Search by package file checksum:
checksum:5afba 

Search by package security status:
severity:critical 

Search by package vulnerabilities:
vulnerabilities:>1 
vulnerabilities:<1000 

Search by # of package downloads:
downloads:>8 
downloads:<100 

Search by package type:
type:binary 
type:source 

Search by package size (bytes):
size:>50000 
size:<10000 

Search by dependency name/version:
dependency:log4j 
dependency:log4j=1.0.0 
dependency:log4j>1.0.0 

Search by uploaded date:
uploaded:>"1 day ago" 
uploaded:<"August 14, 2022 EST" 

Search by entitlement token (identifier):
entitlement:3lKPVJPosCsY 

Search by policy violation:
policy_violated:true
deny_policy_violated:true
license_policy_violated:true
vulnerability_policy_violated:true

Search by repository:
repository:repo-name

Search by last download date:
last_downloaded:<"30 days ago" 
last_downloaded:>"August 14, 2022 EST" 

Search queries for all Debian-specific (and related) package types

Search by component:
deb_component:unstable

Search queries for all Maven-specific (and related) package types

Search by group ID:
maven_group_id:org.apache

Search queries for all Docker-specific (and related) package types

Search by image digest:
docker_image_digest:sha256:7c5..6d4
(full hashref only)

Search by layer digest:
docker_layer_digest:sha256:4c4..ae4
(full hashref only)

Search queries for all Generic-specific package types

Search by file path:
generic_filepath:path/to/file.txt

Search by directory:
generic_directory:path/to

Field type modifiers (depending on the type, you can influence behaviour)

For all queries, you can use:
~foo for negation

For string queries, you can use:
^foo to anchor to start of term
foo$ to anchor to end of term
foo*bar for fuzzy matching

For number/date or version queries, you can use:
>foo for values greater than
>=foo for values greater / equal
<foo for values less than
<=foo for values less / equal

Need a secure and centralised artifact repository to deliver Alpine, Cargo, CocoaPods, Composer, Conan, Conda, CRAN, Dart, Debian, Docker, Generic, Go, Helm, Hex, HuggingFace, LuaRocks, Maven, npm, NuGet, P2, Python, RedHat, Ruby, Swift, Terraform, Vagrant, VSX, Raw & More packages?

Cloudsmith is the new standard in Package / Artifact Management and Software Distribution.

With support for all major package formats, you can trust us to manage your software supply chain.

Start My Free Trial

Python logo article-rec-db  0.0.11

One-liner (summary)

Database models and migrations for the Local News Lab's article recommendation system

Description

_This branch houses the effort to move our DB code to a SQLAlchemy-based stack and is under active development in parallel with the move to Google Analytics 4. For the current production code, see the main branch._

# article-rec-db

<!-- [![Release](https://img.shields.io/github/v/release/LocalAtBrown/article-rec-db)](https://img.shields.io/github/v/release/LocalAtBrown/article-rec-db) --> <!-- [![Build status](https://img.shields.io/github/workflow/status/LocalAtBrown/article-rec-db/merge-to-main)](https://img.shields.io/github/workflow/status/LocalAtBrown/article-rec-db/merge-to-main) -->

[![Python version](https://img.shields.io/badge/python_version-3.9-blue)](https://github.com/psf/black) [![Code style with black](https://img.shields.io/badge/code_style-black-000000.svg)](https://github.com/psf/black) [![More style with flake8](https://img.shields.io/badge/code_style-flake8-blue)](https://flake8.pycqa.org) [![Imports with isort](https://img.shields.io/badge/%20imports-isort-blue)](https://pycqa.github.io/isort/) [![Type checking with mypy](https://img.shields.io/badge/type_checker-mypy-blue)](https://mypy.readthedocs.io) [![License](https://img.shields.io/github/license/LocalAtBrown/article-rec-db)](https://img.shields.io/github/license/LocalAtBrown/article-rec-db)

Database models and migrations for the Local News Lab's article recommendation system.

## Usage

A note before continuing: A lot of the commands you'll see below are wrapped inside [Poe tasks](https://poethepoet.natn.io/index.html) defined in pyproject.toml. Poe is installed as a dev-dependency; run poe --help to get a list of tasks and their descriptions. It's entirely possible to run commands without using Poe, but if you decide to use Poe, make sure to read through the tasks to understand what they do.

### As a package

We use [SQLModel](https://sqlmodel.tiangolo.com/), a layer on top of SQLAlchemy with Pydantic, to define our tables. This is useful because we can import this package to interact with the tables AND have Pydantic objects in Python that correspond to a row in the table.

To install the package from PyPi, run: pip install article-rec-db. Check existing versions [here](https://pypi.org/project/article-rec-db/).

### Database management

We use [Terraform](https://developer.hashicorp.com/terraform) to manage cluster entities such as databases, roles and extensions. The code is in the terraform directory. Stages (dev and prod) are represented as different databases. To make changes to an existing database,

  1. Make changes inside terraform/modules.
  2. Run poe terraform [stage] plan to see the changes that will be applied to the corresponding database.
  3. At this point, if you're happy, you can run poe terraform [stage] apply yourself, but we prefer a CI/CD approach. Merging a PR to the dev branch will trigger a plan to be applied to the dev database, and the same for the prod branch. _We always merge to dev first, then do another merge from dev to prod._

### Table and column migrations

So you made some changes to what tables there are, what columns there are, indices, etc. and you'd like to update the databases. This is what alembic is for! (And notice the difference between Terraform and alembic: Terraform manages database entities that are not specific to a database, like roles and extensions, while alembic manages database entities that are specific to a database, like tables and columns.)

To generate a new revision after you've updated the models:

  1. Run this from the root of the project: DB_CONNECTION_STRING='postgresql://user:password@host:port/db_name' alembic revision --autogenerate -m "message". (There's a Poe task for this: run poe rmtdiff -d db_name -m "message")
  2. Check the /alembic/versions/ directory for the new revision and verify that it does what you want it to. Run TYPE=alembic poe test to test models against a local DB initialized via Alembic, and resolve issues as needed.
  3. Run this from the root of the project: DB_CONNECTION_STRING='postgresql://user:password@host:port/db_name' alembic upgrade head. Note that you only need to generate the revision file (step 1) _once_ because we want the same content in each environment's database, but you do need to run the upgrade head command once _for each_ database (change the DB_NAME to the desired target). (There's a Poe task for this: run poe rmtupgrade -d db_name)

Similar to database management, we let our CI/CD handle Step 3.

_Note to LNL devs: Our automated deployment process will run the Terraform changes first, then the Alembic changes. So, for example, using Terraform to create a new database and Alembic to create a new table in that database will work in just one PR, but creating a new table with Alembic and using Terraform to grant a role access to that table won't. Best to divide changes into atomic units, each handled by a single PR._

## Development

This project uses [Poetry](https://python-poetry.org/) to manage dependencies. It also helps with pinning dependency and python versions. We also use [pre-commit](https://pre-commit.com/) with hooks for [isort](https://pycqa.github.io/isort/), [black](https://github.com/psf/black), and [flake8](https://flake8.pycqa.org/en/latest/) for consistent code style and readability. Note that this means code that doesn't meet the rules will fail to commit until it is fixed.

We use [mypy](https://mypy.readthedocs.io/en/stable/index.html) for static type checking. This can be run [manually](#run-static-type-checking), and the CI runs it on PRs to the main branch. We also use [pytest](https://docs.pytest.org/en/7.2.x/) to run our tests. This can be run [manually](#run-tests) and the CI runs it on PRs to the main branch.

### Setup

  1. [Install Poetry](https://python-poetry.org/docs/#installation).
  2. Run poetry install --no-root
  3. Run source $(poetry env list --full-path)/bin/activate && pre-commit install && deactivate to set up pre-commit

You're all set up! Your local environment should include all dependencies, including dev dependencies like black. This is done with Poetry via the poetry.lock file.

### Run Code Format and Linting

pre-commit run --all-files runs isort, black, and flake8 all in one go, and is also run on every commit.

poe format does what pre-commit run --all-files does and also formats the Terraform code.

### Run Static Type Checking

To manually run mypy, simply run mypy from the root directory of the project. It will use the default configuration specified in pyproject.toml.

### Update Dependencies

To update dependencies in your local environment, make changes to the pyproject.toml file then run poetry update from the root directory of the project.

To update Terraform dependencies, make changes to versions.tf files as necessary.

### Run Tests

To manually run rests, you need to have a Postgres instance running locally on port 5432. One way to do this is to run a Docker container, then run the tests while it is active.

  1. (If you don't already have the image locally) Run docker pull ankane/pgvector:v<version used in your remote db>
  2. Run docker run --rm --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -p 127.0.0.1:5432:5432/tcp postgres
  3. Run pytest tests from the root directory of the project. Explore the pytest docs (linked above)

Note that if you decide to run the Postgres container with different credentials (a different password, port, etc.) or via a different method, you will likely need to update the test file to point to the correct Postgres instance.

Additionally, if you want to re-run the tests, you want to make sure you start over from a fresh Postgres instance. If you run Postgres via Docker, you can simply ctrl-C to stop the image and start a new one.

Steps 2 and 3 can be combined into one Poe task: poe test, which also stops the container after the tests are done, even if tests fail. In addition, you can also run poe lclstart to just start the container, and poe lclstop to stop it whenever you're done. poe lclconnect will connect you to the container via psql so you can poke around.

poe test, by default, is equivalent to TYPE=sqlmodel poe test, which tests the models against a local DB initialized via SQLModel. You can also run TYPE=alembic poe test to test the models against a local DB initialized via Alembic. The first is more convenient and is good for development, the second reflects the production environment more closely and is good for testing Alembic revisions once you're about to submit a PR.

Size

10.9 KB

Downloads

5

Status  Completed
Checksum (MD5) 08de2e44abb01b1a9e49b4c2df5b4a01
Checksum (SHA-1) 3a1e082eb9953c2a93f929a9821651dfbf2e5946
Checksum (SHA-256) d706ec6cec3a5f7a90449a4abfe27b436d09423195abccd12cee42605d11d8fd
Checksum (SHA-512) b2f5858f92e8bad4dd24af3ca7ea59827362b924f87a768268122f43f980b7dd2f…
GPG Signature
GPG Fingerprint 6811684bac0b8895434e97bdd4391b8fb999e537
Storage Region  Dublin, Ireland
Type  Binary (contains binaries and binary artifacts)
Uploaded At 4 months, 2 weeks ago
Uploaded By Fetched by Cloudsmith
Slug Id article_rec_db-0011-py3-none-anywhl-efqp
Unique Id I7EOrYHNQFK5XDKN
Version (Raw) 0.0.11
Version (Parsed)
  • Major: 0
  • Minor: 0
  • Patch: 11
  • Type: SemVer (Compat)
  extended metadata
Author Duy Nguyen <hello.duyknguyen@gmail.com>
Classifiers License :: OSI Approved :: MIT License | Programming Language :: Python :: 3 | Programming Language :: Python :: 3.10 | Programming Language :: Python :: 3.11 | Programming Language :: Python :: 3.9
Homepage URL https://github.com/LocalAtBrown/article-rec-db/
Metadata Version 2.1
Project Urls Documentation, https://github.com/LocalAtBrown/article-rec-db/ | Repository, https://github.com/LocalAtBrown/article-rec-db/
Py Filetype bdist_wheel
Py Version py3
Requires Dist numpy (>=1.26.1,<2.0.0) | pgvector (>=0.2.3,<0.3.0) | psycopg2 (>=2.9.9,<3.0.0) | pydantic (>=2.5.0,<3.0.0) | sqlalchemy (>=2.0.0,<3.0.0) | sqlmodel (>=0.0.14,<0.0.15)
Requires Python >=3.9,<3.12
pkg article_rec_db-0.0.11-py3-none-… 5
10.9 KB
md5 sha1 sha256 sha512
Package Contents (article_rec_db-0.0.11-py3-none-any.whl)
Loading...

This package has 17 files/directories.

Last scanned

4 months, 2 weeks ago

Scan result

Clean

Vulnerability count

0

Max. severity

Unknown

You can embed a badge in another website that shows this or the latest version of this package.

To embed the badge for this specific package version, use the following:

[![This version of 'article-rec-db' @ Cloudsmith](https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true)](https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/)
|This version of 'article-rec-db' @ Cloudsmith|
.. |This version of 'article-rec-db' @ Cloudsmith| image:: https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true
   :target: https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/
image::https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true[link="https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/",title="This version of 'article-rec-db' @ Cloudsmith"]
<a href="https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/"><img src="https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/0.0.11/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true" alt="This version of 'article-rec-db' @ Cloudsmith" /></a>

rendered as: This version of 'article-rec-db' @ Cloudsmith

To embed the badge for the latest package version, use the following:

[![Latest version of 'article-rec-db' @ Cloudsmith](https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true&show_latest=true)](https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/)
|Latest version of 'article-rec-db' @ Cloudsmith|
.. |Latest version of 'article-rec-db' @ Cloudsmith| image:: https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true&show_latest=true
   :target: https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/
image::https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true&show_latest=true[link="https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/",title="Latest version of 'article-rec-db' @ Cloudsmith"]
<a href="https://cloudsmith.io/~demo-docs/repos/awesome-repo/packages/detail/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/"><img src="https://api.cloudsmith.com/v1/badges/version/demo-docs/awesome-repo/python/article-rec-db/latest/a=noarch;xf=bdist_wheel;xn=article-rec-db;xv=py3/?render=true&show_latest=true" alt="Latest version of 'article-rec-db' @ Cloudsmith" /></a>

rendered as: Latest version of 'article-rec-db' @ Cloudsmith

These instructions assume you have setup the repository first (or read it).

To install/use article-rec-db @ version 0.0.11 ...

pip install 'article-rec-db==0.0.11'

You can also install the latest version of this package:

pip install --upgrade 'article-rec-db'

If necessary, you can specify the repository directly:

pip install \
  --index-url=https://dl.cloudsmith.io/public/demo-docs/awesome-repo/python/simple/ \
  article-rec-db==0.0.11

If you've got a project requirements.txt file, you can specify this as a dependency:

--index-url=https://dl.cloudsmith.io/public/demo-docs/awesome-repo/python/simple/
article-rec-db==0.0.11

In addition, you can use this repository as an extra index url. However, please read our documentation on this parameter before using it. For example in a requirements.txt file:

--extra-index-url=https://dl.cloudsmith.io/public/demo-docs/awesome-repo/python/simple/
article-rec-db==0.0.11
Warning: We highly recommend using pip (or similar) rather than installing directly.
Top