MatchDB Core

Suggesting people to connect with based on shared interests

PyMatch is a database of users and their interests. Given a user from its database, it will search and return others with matching/mutual interests

What data will be stored?

Note: This project is using a serverless NoSQL database called Base by deta.sh. It’s free, has unlimited storage and is easy to use!

  • Dates are UTC in the format dd-mm-yyyy hh:00, in code this is %d-%m-%Y %H:00 (see Python strftime cheatsheet for more formats).
  • user_id is a unique identifier for each user and group_id is for the group/server they belong to.
  • ULIDs (Universally Unique Lexicographically Sortable Identifiers) are used as keys and order is is preserved since data in Bases are ordered by key; key is required by Deta and needs to be unique.
  • Interests are a list of strings.

Users

Info stored for each user

[{'date': '02-10-2022 17:00',
  'key': '01BJQMF54D093DXEAWZ6JYRPAQ,
  'user_id': '1111',
  'group_id': '2222',
  'name': 'cameronson the 69th',
  'interests': ['MMA', 'memes', 'Uk', 'tea']}]

A Deta project key is needed, create one on https://deta.space and save it as an environament variable.

Note: it’ll be convenient if you save the env variable as “DETA_PROJECT_KEY” since that’s the default argument for the project_key parameter in all the functions that use it

Users

Add


source

add_someone

 add_someone (user_id:str, database_name:str, interests:List[str],
              group_id:Optional[str]=None,
              project_key:str='DETA_PROJECT_KEY')

Create a new user and add their interests. Will be used by add_interests.

All interests will be made lowercase.

Type Default Details
user_id str unique identifier to authenticate users
database_name str create or connect to an existing database
interests typing.List[str]
group_id typing.Optional[str] None id for the group/server the user is from
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored

Find


source

find_user

 find_user (user_id:str, database_name:str, group_id:Optional[str]=None,
            project_key:str='DETA_PROJECT_KEY')

Find all data on a user from thier user_id and/or group_id.

Type Default Details
user_id str
database_name str
group_id typing.Optional[str] None id for the group/server the user is from
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored
Returns typing.List[dict]

Delete


source

delete_user

 delete_user (user_id:str, database_name:str,
              project_key:str='DETA_PROJECT_KEY')

Deletes an entry using thier user_id if they exist

Type Default Details
user_id str
database_name str
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored

Interests

Show a user’s interests


source

show_interests

 show_interests (user_id:str, database_name:str, group_id:str,
                 project_key:str='DETA_PROJECT_KEY')

Gets a list of interests for a given user within a group_id. Uses find_user.

Type Default Details
user_id str unique identifier
database_name str
group_id str id for the group/server the user is from
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored
Returns typing.List[str]

Add


source

add_interests

 add_interests (user_id:str, interests:List[str], database_name:str,
                group_id:Optional[str]=None,
                project_key:str='DETA_PROJECT_KEY')

Add new interests to a user if they exist or creates a new user using add_someone if they don’t.

Type Default Details
user_id str unique identifier to authenticate users
interests typing.List[str]
database_name str create or connect to an existing database
group_id typing.Optional[str] None id for the group/server the user is from
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored

Delete interests


source

delete_interests

 delete_interests (user_id:str, remove_interests:List[str],
                   database_name:str, group_id:Optional[str]=None,
                   project_key:str='DETA_PROJECT_KEY')

Delete interest(s). If group_is is None then interests of the user will be deleted in all groups.

Type Default Details
user_id str unique identifier to authenticate users
remove_interests typing.List[str]
database_name str create or connect to an existing database
group_id typing.Optional[str] None id for the group/server the user is from
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored

Match


source

match_interests

 match_interests (user_id:str, database_name:str,
                  project_key:str='DETA_PROJECT_KEY')

Match users to a given user_id and return names and common/shared interests

Type Default Details
user_id str
database_name str
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored
Returns typing.List[dict]

Stats

Get whole database


source

database_exists

 database_exists (database_name:str, project_key:str='DETA_PROJECT_KEY')

check if db exists by checking if there’s at least one item

Type Default Details
database_name str
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored
Returns bool

source

fetch_all

 fetch_all (database_name:str, project_key:str='DETA_PROJECT_KEY')

fetches the whole database

this is from deta’s docs: https://docs.deta.sh/docs/base/sdk/#fetch-all-items-1

uses database_exists

Type Default Details
database_name str
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored
Returns typing.List[dict]

source

database_to_dataframe

 database_to_dataframe (database_name:str,
                        project_key:str='DETA_PROJECT_KEY')

fetches the whole database and converts it to a pandas dataframe

uses fetch_all

Type Default Details
database_name str
project_key str DETA_PROJECT_KEY the environment variable name where your Deta project key is stored
Returns DataFrame

Count interests


source

count_interests

 count_interests (database_name:str='users')

Shows each interest and how many times they occur. If needed, this can work for any column that contains a list of strings.

Uses database_to_dataframe


source

interestcount_to_dataframe

 interestcount_to_dataframe (database_name:str='users')

Get interest counts as a pandas dataframe

Uses database_to_dataframe

User stats


source

total_users

 total_users (database_name:str)

Count total users. Uses fetch_all