Coroutine Data Access Patterns (mouthful I know) are some data access patterns I found useful building web applications that use gevent or evenlet. They mimic common Python data types like lists and dictionaries.
Project description
codap
=====
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 :(.
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:
```python
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:
```python
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:
```python
def get_data(id):
return my_data[id]
fr = codap.FirstReply()
for ds in datasource_list:
fr.push(get_data, id)
data = fr[0]
```
=====
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 :(.
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:
```python
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:
```python
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:
```python
def get_data(id):
return my_data[id]
fr = codap.FirstReply()
for ds in datasource_list:
fr.push(get_data, id)
data = fr[0]
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
codap-0.0.1.tar.gz
(4.1 kB
view details)
File details
Details for the file codap-0.0.1.tar.gz
.
File metadata
- Download URL: codap-0.0.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab062a1f0e837a37ddcbf132128b03e35ba7cbece006574b20cf32fc0faea444 |
|
MD5 | 5260f5e46ccc664c086712a0895ea9e1 |
|
BLAKE2b-256 | 4bde14076ed77652d9de9350db506ece336f0cb48d0a3102aa1c0fcd6c48dcec |