A set of simple draft adapters allowing the PyOWM library to leverage external cache systems. The code relies on the Python bindings for the adapted system.
More to come...
MIT license
- Of course, you need to install the PyOWM library before :-) Use pip
- Install the Python bindings for the cache system/s you need to adapt:
- Download the adapters package
- Place it somewhere you can reach via your
PYTHONPATH
variable (the PyOWM installation folder is OK)
There are two ways...
-
Wire the adapters into a configuration module that you setup and put in a location reachable from your
PYTHONPATH
. Eg: say your config file ismypyowmconfig/myconfig.py
andmypyowmconfig
is somewhere in yourPYTHONPATH
:# Content of your own PyOWM config module from pyowm-cache-adapters import redis_adapter # This is where you installed the adapters cache = nullcache.RedisAdapter() # [...] (other config values)
-
Instantiate the library injecting a reference to your own config module. Eg:
import pyowm owm = pyowm.OWM(None, None, 'mypyowmconfig.myconfig') # This loads the config values from your module
More about PyOWM config module on the PyOWM wiki.
-
Find the
configurationXX.py
file which is specific for the web API version you are currently using. This will likely be in/usr/local/lib/python2.6/dist-packages/pyowm/webapi25/config25.py
for Unix-like envs or inC:\Python27\Lib\site-packages\pyowm\webapi25\config25.py
for Windows envs. -
Open the file and spot this line:
# Cache provider to be used cache = NullCache()
and change it accordingly to the adapter you need. In example, for Memcached:
# Cache provider to be used # cache = NullCache() # <--- comment/remove this line from pyowm_cache_adapter.memcached_adapter import MemcachedAdapter cache = MemcachedAdapter( [... parameters ...] )
(be careful not to miss the
import
statement)
The provided adapters are just intended to be drafts: modify them accordingly to your application-specific needs.
There's only one thing that you must bear in mind: each adapter must subclass the
the pyowm.abstractions.owmcache.OWMCache
abstract class for it to work into the PyOWM library.
Please signal any bugs you may encounter.