GithubHelp home page GithubHelp logo

amsterdam / typeahead Goto Github PK

View Code? Open in Web Editor NEW
1.0 27.0 0.0 115 KB

Typeahead search for many datasets through a single endpoint

Home Page: https://api.data.amsterdam.nl/typeahead/openapi

License: Mozilla Public License 2.0

Python 92.31% Makefile 6.89% Dockerfile 0.80%
python aiohttp team-datadiensten

typeahead's Introduction

Typeahead service

Typeahead searches accross Datapunt APIs.

Run on your machine using:

$ pip install git+https://github.com/Amsterdam/typeahead
$ typeahead --config example.config.yml

Development / Local Testing

$ git clone [email protected]:Amsterdam/typeahead.git
$ cd typeahead

# create a virtualenv, then...

$ pip install -e .[dev,test]
$ typeahead --config example.config.yml

Design

Search endpoint

The root of the application, '/', is the search endpoint. It supports a q parameter only. Also see the info on our OpenAPI spec below.

Note that the order of the results reflect the order of the endpoints in the configuration. The importance of the order of the results is an artefact of a design mistake we have to live with for now.

Also note that the content type of the response bears slight resemblance to HAL JSON, but really isn't. This is again due to

Setuptools

Typeahead is an installable Python module. After installing (see example above), it provides the typeahead command, which executes the typeahead.main module. See setup.py for all settings.

Async HTTP

Typeahead uses asyncio and runs uvloop as its eventloop. We use aiohttp as both http server, to serve requests on many concurrent connections, and http client, to fetch search results from downstream endpoints in parallel.

In typeahead.application you can find our aiohttp.web.Application, including the routes. Note that we ship some CORS-related code in typeahead.application that will hopefully soon be provided externally.

In typeahead.handlers.* you find the handlers for all endpoints.

Configuration

Configuration is provided through a configuration file in YAML format. The JSON schema is provided in typeahead.config_schema.yml.

Module typeahead.config provides a load(path) mathod to load configuration. It will read the yaml, interpolate placeholders with the environment, validate the schema and then return the loaded configuration. This greatly reduces the need for validation of the provided configuration.

Docker, Jenkins, make

At Amsterdam, we run the code in a docker container. Our deployment pipeline is described in the provided Jenkinsfile. Use the Makefile for repetitive tasks, such as cleaning up and running tests.

Metrics

Typeahead publishes Prometheus metrics on the /metrics endpoint. Metrics include:

metric type labels
request_processing_seconds summary
search_exceptions_total counter endpoint, exc_type
search_responses_total counter endpoint, status

Note that this endpoint will always run directly under the root, and will not keep the baseurl in mind. This allows us to publish the metrics only internally.

OpenAPI

Typeahead publishes its own API on the /openapi endpoint.

typeahead's People

Contributors

aditudorache avatar bheupers avatar daveneijsen avatar dolhuis avatar evertlammerts avatar ichnograph avatar jjmurre avatar pieterb avatar spreeker avatar stephanzaat avatar thijs-creemers avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.