Giter Club home page Giter Club logo

bloomapi's Introduction

BloomAPI

Hi! In this repo is stored the BloomFilter API that we've created for our Data Structures class

Installation

In order to use this API, first clone the repository via http/ssh or download the zip in the <>code section. In this example, we'll clone the repository via ssh:

git clone [email protected]:J-Povea21/BloomAPI.git

Once you've cloned the repo, install the necessary dependencies. You can do it by using the requeriements.txt file:

pip install -r requirements.txt

Database and migrations

The idea of this implementation is to use a database and show how we can reduce the amount of queries to the database using the bloom filter. You can use whatever database you like, but in this case we're going to use sqlite3, SQLAlchemy and alembic to manage the migrations and the database.

Set an url for the database

In the database.py file located in the src/db folder you'll find a variable called DB_URL that is set to a default value. Right now, it looks like this:

DB_URL = "sqlite:///./DB_NAME.sqlite3"

You'll need to change the DB_NAME part to the name of the database you created in the previous step (in case you're using sqlite3, of course)

Creating the migrations

Fine! Now we're gonna use alembic to create the migrations. The first step is create an alembic.ini file. To do this, run the following command:

alembic init migration_folder

The migration_folder is the name of the folder where you want to allocate the migrations. In this case, we're gonna called migrations. At this point, our project structure should look like this:

```
alembic.ini
migrations/
        other_files.py
src/
   other_folders/

```

Running the first migration

Now, we're gonna create the first migration. To do this, run the following command:

alembic revision -m "First migration"

This will create a file in the migrations/versions folder. This file will have a name like this: _first_migration.py. Open this file and you'll see a function called upgrade(). This function is where you'll write the code to create the tables in the database. In this case, we need to create a table called users with the columns id, username , password and is_active:

def upgrade() -> None:
    op.create_table(
        'users',
        sa.Column('id', sa.Integer, primary_key=True, index=True),
        sa.Column('username', sa.String, unique=True, index=True),
        sa.Column('password', sa.String),
        sa.Column('is_active', sa.Boolean, default=True)
    )


def downgrade() -> None:
    op.drop_table('users') # This one is a fn we can use if we want to go back

With this, you can run the migration. To do this, run the following command:

alembic upgrade head

where head is the most recent revision. Note that the upgrade argument is basically calling the upgrade() function in our revision file which is the one that is creating the table in the database.

Testing

With this, you're done! To test the API, run the following command and test the different methods in the docs route (http://localhost:8000/docs):

uvicorn src.main:app --reload

Members of the project

Finally, these are the members of the project:

  • Juan Andrés Povea
  • Jesús David Cantillo
  • Yovany Zhu
  • Carlos Elías López

bloomapi's People

Contributors

j-povea21 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.