Giter Site home page Giter Site logo

codap's Introduction

codap

Travis Build Status

Coroutine Data Access Patterns (codap) are a handful of libraries to make concurrent data access simpler to use. This was originally developed for web services access data in mutliple datastores (MongoDB, S3, REST, ect). The library uses async methods (thread, eventlet or gevent) which degrades gracefully. Perfering gevent, eventlet and falling back to threading. One of those things it would be really nice to have anonymous functions in Python :(.

INSTALL

pip install codap

Key / Value (Dictionary)

Allows for a dictionary like access. This is great for caches, template rendering and since dictionaries are the most used data type it is easy to integrate into existing code.

Example:

def back(db, name):
  return db.find(name)

results = KV()
results['foo'] = bar # bar is a function
results.put('cats', get_photos, id, limit=4) # get_photos is a function
results.put('monkey', back, db, name)
render_template('my_temp.html', **results)

Ordered List

List that returns the responses based on the order they are added. Has been used for retrieving already sorted data that needs additional information to be rendered.

Example:

def get_stuff(db, x):
  return db.get(x)

results = codap.Ordered()
for x in xrange(0, 10):
  results.push(get_stuff, db, x)
for r in results: # Same order as pushed
  r.render()

First Reply

Based on the order of the response is the order it is added to the list. Useful for making request to multiple databases. Has been used for getting a list of files from a web service and compressing them into a single zip or tar.

Example:

def get_data(id):
  return my_data[id]

fr = codap.FirstReply()
for ds in datasource_list:
  fr.push(get_data, id)
data = fr[0]

Fibonacci Example (full):

import codap


def fib(n):
    if n == 1:
        return 1
    elif n == 0:
        return 0
    else:
        return fib(n - 1) + fib(n - 2)

FIB_SIZE = 30
d = codap.KV()
# Push a bunch of fib processing into the background
for i in range(0, FIB_SIZE):
    d.put(i, fib, i)

# Pull them out from the list
for i in range(0, FIB_SIZE):
    assert d[i] == fib(i), 'Expected fib {0} to be {1} but was {3}'.format(i, d[i], fib(i))

d = codap.Ordered()
for i in range(0, FIB_SIZE):
    d.push(fib, i)

i = 0
for f in d:
    assert f == fib(i), 'Expected fib {0} to be {1} but was {3}'.format(i, f, fib(i))
    i += 1

codap's People

Contributors

lateefj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

codap's Issues

Add coverage support

Adding coverage support would be nice just to know what code is not covered in the tests.

Thread Queue Iterator Wrapper

The gevent queue works great when iterating over it. However the thread Queue is not design for this type of use case. Write a wrapper around this to make the Thread Queue suck a little less.

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.