Giter VIP home page Giter VIP logo

jinx's Introduction

jinx

Fast and simple indexing for JSON Lines files, complete with a built-in Sanic web server for speedy lookups over HTTP. Berkeley DBs are used under the hood for the indexes.

For trying jinx out on an Ubuntu machine, you can get started like so:

$ apt-get install libdb5.3-dev

$ virtualenv --python=python3 env
$ env/bin/python setup.py develop

$ env/bin/jinx --help

On a Mac, you might want to use brew to install berkeley-db and then point to it using the BERKELEYDB_DIR environment variable while executing setup.py, e.g.:

BERKELEYDB_DIR=/usr/local/opt/berkeley-db@4/ env/bin/python setup.py develop

Once you got this sorted, you're ready to jinx some files. Here's a simple example:

$ cat players.jsonl
{"name": "lukaku", "country": "belgium",  "goals": 73, "matches": 80}
{"name": "hazard", "country": "belgium", "goals": 53, "matches": 86}

$ env/bin/jinx index players.jsonl -k name
$ ls players.*
players.jsonl
players.jsonl.jinx

$ env/bin/jinx lookup players.jsonl hazard
{"name": "hazard", "country": "belgium", "goals": 53, "matches": 86}
$ env/bin/jinx lookup players.jsonl hazard lukaku
{"name": "hazard", "country": "belgium", "goals": 53, "matches": 86}
{"name": "lukaku", "country": "belgium", "goals": 73, "matches": 80}

You can also group your lookup keys by specifying a prefix field:

$ env/bin/jinx index players.jsonl -k name -p country

$ env/bin/jinx lookup players.jsonl belgium:hazard
{"name": "hazard", "country": "belgium", "goals": 53, "matches": 86}
$ env/bin/jinx lookup players.jsonl -p belgium hazard
{"name": "hazard", "country": "belgium", "goals": 53, "matches": 86}

And there's nifty built-in web server for doing lookups over HTTP as well:

$ env/bin/jinx serve -h 127.0.0.1 -p 8000 -d .

$ curl http://127.0.0.1:8000/players/belgium:hazard
[{"name":"hazard","country":"belgium","goals":53,"matches":86}]
$ curl http://127.0.0.1:8000/players/belgium/hazard
[{"name":"hazard","country":"belgium","goals":53,"matches":86}]
$ curl http://127.0.0.1:8000/players/belgium/hazard,lukaku
[{"name":"hazard","country":"belgium","goals":53,"matches":86},{"name":"lukaku","country":"belgium","goals":73,"matches":80}]

If you change your data while the web server is running, you can reload via a PATCH request:

$ curl -X PATCH http://127.0.0.1:8000/players

or simply:

$ curl -X PATCH http://127.0.0.1:8000

This gets even cooler when combined with using directories. When you have a directory like e.g.

$ ls players/
20181025.jsonl
20181025.jsonl.jinx

you can do lookups on the directory and jinx will automatically use the latest (indexed) JSON Lines file in that directory (based on sorting them alphanumerically). So whenever you want to update your data, you can simply add new files to the directory and switch atomically by sending a PATCH request. And if you want to switch back to the old data, you can simply remove the new files and reload again.

jinx's People

Contributors

klbostee avatar

Watchers

James Cloos avatar Michiel Van den Berghe 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.