%global _empty_manifest_terminate_build 0 Name: python-DB-Transfer Version: 0.5.6 Release: 1 Summary: An easy way to fetch and store data from and store to key-value databases like Redis. License: MIT URL: https://github.com/arrrlo/db-transfer Source0: https://mirrors.aliyun.com/pypi/web/packages/33/1c/e4c75fb2ae919cabb15b02401979b9c45384aae2907716a885cd2e32ecd7/DB%20Transfer-0.5.6.tar.gz BuildArch: noarch Requires: python3-click Requires: python3-redis Requires: python3-ujson Requires: python3-six Requires: python3-PyYAML %description
An easy way to manipulate data using key-value databases like Redis.
It is designed to support a number of databases, but currently Redis and yaml file are supported.
There are an adapter class for every database.
After instantiating Python Transfer using certain adapter_name, we can manipulate the
data from key-value database just like dictionaries: `transfer[key] = value`
Keys are created using prefix, namespace and item.
Example: data:USERS:arrrlo:full_name
(data is prefix, USERS is namespace and arrrlo:full_name is item)
Very handy when using in docker containers.
```python from db_transfer import Transfer, sent_env os.environ['REDIS_HOST'] = 'localhost' os.environ['REDIS_PORT'] = '6379' os.environ['REDIS_DB'] = '0' @sent_env('redis', 'HOST', 'REDIS_HOST') @sent_env('redis', 'PORT', 'REDIS_PORT') @sent_env('redis', 'DB', 'REDIS_DB') class RedisTransfer(Transfer): def __init__(self, prefix=None, namespace=None): super().__init__(prefix=str(prefix), namespace=namespace, adapter_name='redis') ```Every key in Redis is stored in set in same Redis.
Example:
So, the keys are "key_1", "key_2:key3", "key_2:key4", "key_2:key5:key_6", "key_2:key5:key_7", "key_2:key5:key_8".
They are not stored in one set, but different keys are stored i different sets:
'my_prefix:my_namespace': set({'key_1', 'key_2:keys'})
'my_prefix:my_namespace:key_2': set({'key_3', 'key_4', 'key_5:keys'})
'my_prefix:my_namespace:key_2:key_5': set({'key_6', 'key_7', 'key_8'})
This is done this way so you can easily access data by keys fom any level recursively:
Transfer all data from one Redis database to another:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) rt_2 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='some_host', port=6379, db=0) for key in rt_1.keys(): rt_2[key] = rt_1[key] ```or if you want to insert data in one batch (read goes one by one):
```python with rt_2: for key in rt_1.keys(): rt_2[key] = rt_1[key] ```Transfer data from one user to another:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) for key in rt_1['arrrlo'].keys(): rt_1['edi:' + key] = rt_1['arrrlo:' + key] ```Delete user from database:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) with rt_1: for key in rt_1['arrrlo'].keys(): del rt_1['arrrlo:' + key] ```Initially the data from yaml file transferes from file to memory.
From there every read, write or delete runs until the sync() method
is called. Then the data from memory is transfered to yaml file.
sync() method could be called using context manager or manually.
Very handy when using in docker containers.
```python from db_transfer import Transfer, sent_env os.environ['YAML_FILE_PATH'] = '/path/to/yaml/file.yaml' @sent_env('yaml', 'FILE_LOCAL', 'YAML_FILE_PATH') class YamlFileTransfer(Transfer): def __init__(self, prefix=None, namespace=None): super().__init__(prefix=str(prefix), namespace=namespace, adapter_name='yaml') ```Data could be written using context manager or sync() method.
```python yt = YamlFileTransfer(prefix='my_prefix', namespace='my_namespace', yaml_file_path='/path/') with yt: yt['my_key_1'] = 'some_string' yt['my_key_2'] = 'some_string' yt.sync() with yt: del yt['my_key_1'] del yt['my_key_2'] yt.sync() ```Backup user data from Redis to yaml file:
```python rt = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix', namespace='my_namespace', yaml_file_path='/path/') for key in rt['arrrlo'].keys(): yt['arrrlo:' + key] = rt['arrrlo:' + key] # or (depends on how you use prefix and namespace): rt = RedisTransfer(prefix='users', namespace='arrrlo', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='users', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt[key] # or: rt = RedisTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt[key] # or: rt = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt['arrrlo:' + key] ``` %package -n python3-DB-Transfer Summary: An easy way to fetch and store data from and store to key-value databases like Redis. Provides: python-DB-Transfer BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-DB-TransferAn easy way to manipulate data using key-value databases like Redis.
It is designed to support a number of databases, but currently Redis and yaml file are supported.
There are an adapter class for every database.
After instantiating Python Transfer using certain adapter_name, we can manipulate the
data from key-value database just like dictionaries: `transfer[key] = value`
Keys are created using prefix, namespace and item.
Example: data:USERS:arrrlo:full_name
(data is prefix, USERS is namespace and arrrlo:full_name is item)
Very handy when using in docker containers.
```python from db_transfer import Transfer, sent_env os.environ['REDIS_HOST'] = 'localhost' os.environ['REDIS_PORT'] = '6379' os.environ['REDIS_DB'] = '0' @sent_env('redis', 'HOST', 'REDIS_HOST') @sent_env('redis', 'PORT', 'REDIS_PORT') @sent_env('redis', 'DB', 'REDIS_DB') class RedisTransfer(Transfer): def __init__(self, prefix=None, namespace=None): super().__init__(prefix=str(prefix), namespace=namespace, adapter_name='redis') ```Every key in Redis is stored in set in same Redis.
Example:
So, the keys are "key_1", "key_2:key3", "key_2:key4", "key_2:key5:key_6", "key_2:key5:key_7", "key_2:key5:key_8".
They are not stored in one set, but different keys are stored i different sets:
'my_prefix:my_namespace': set({'key_1', 'key_2:keys'})
'my_prefix:my_namespace:key_2': set({'key_3', 'key_4', 'key_5:keys'})
'my_prefix:my_namespace:key_2:key_5': set({'key_6', 'key_7', 'key_8'})
This is done this way so you can easily access data by keys fom any level recursively:
Transfer all data from one Redis database to another:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) rt_2 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='some_host', port=6379, db=0) for key in rt_1.keys(): rt_2[key] = rt_1[key] ```or if you want to insert data in one batch (read goes one by one):
```python with rt_2: for key in rt_1.keys(): rt_2[key] = rt_1[key] ```Transfer data from one user to another:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) for key in rt_1['arrrlo'].keys(): rt_1['edi:' + key] = rt_1['arrrlo:' + key] ```Delete user from database:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) with rt_1: for key in rt_1['arrrlo'].keys(): del rt_1['arrrlo:' + key] ```Initially the data from yaml file transferes from file to memory.
From there every read, write or delete runs until the sync() method
is called. Then the data from memory is transfered to yaml file.
sync() method could be called using context manager or manually.
Very handy when using in docker containers.
```python from db_transfer import Transfer, sent_env os.environ['YAML_FILE_PATH'] = '/path/to/yaml/file.yaml' @sent_env('yaml', 'FILE_LOCAL', 'YAML_FILE_PATH') class YamlFileTransfer(Transfer): def __init__(self, prefix=None, namespace=None): super().__init__(prefix=str(prefix), namespace=namespace, adapter_name='yaml') ```Data could be written using context manager or sync() method.
```python yt = YamlFileTransfer(prefix='my_prefix', namespace='my_namespace', yaml_file_path='/path/') with yt: yt['my_key_1'] = 'some_string' yt['my_key_2'] = 'some_string' yt.sync() with yt: del yt['my_key_1'] del yt['my_key_2'] yt.sync() ```Backup user data from Redis to yaml file:
```python rt = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix', namespace='my_namespace', yaml_file_path='/path/') for key in rt['arrrlo'].keys(): yt['arrrlo:' + key] = rt['arrrlo:' + key] # or (depends on how you use prefix and namespace): rt = RedisTransfer(prefix='users', namespace='arrrlo', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='users', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt[key] # or: rt = RedisTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt[key] # or: rt = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt['arrrlo:' + key] ``` %package help Summary: Development documents and examples for DB-Transfer Provides: python3-DB-Transfer-doc %description helpAn easy way to manipulate data using key-value databases like Redis.
It is designed to support a number of databases, but currently Redis and yaml file are supported.
There are an adapter class for every database.
After instantiating Python Transfer using certain adapter_name, we can manipulate the
data from key-value database just like dictionaries: `transfer[key] = value`
Keys are created using prefix, namespace and item.
Example: data:USERS:arrrlo:full_name
(data is prefix, USERS is namespace and arrrlo:full_name is item)
Very handy when using in docker containers.
```python from db_transfer import Transfer, sent_env os.environ['REDIS_HOST'] = 'localhost' os.environ['REDIS_PORT'] = '6379' os.environ['REDIS_DB'] = '0' @sent_env('redis', 'HOST', 'REDIS_HOST') @sent_env('redis', 'PORT', 'REDIS_PORT') @sent_env('redis', 'DB', 'REDIS_DB') class RedisTransfer(Transfer): def __init__(self, prefix=None, namespace=None): super().__init__(prefix=str(prefix), namespace=namespace, adapter_name='redis') ```Every key in Redis is stored in set in same Redis.
Example:
So, the keys are "key_1", "key_2:key3", "key_2:key4", "key_2:key5:key_6", "key_2:key5:key_7", "key_2:key5:key_8".
They are not stored in one set, but different keys are stored i different sets:
'my_prefix:my_namespace': set({'key_1', 'key_2:keys'})
'my_prefix:my_namespace:key_2': set({'key_3', 'key_4', 'key_5:keys'})
'my_prefix:my_namespace:key_2:key_5': set({'key_6', 'key_7', 'key_8'})
This is done this way so you can easily access data by keys fom any level recursively:
Transfer all data from one Redis database to another:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) rt_2 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='some_host', port=6379, db=0) for key in rt_1.keys(): rt_2[key] = rt_1[key] ```or if you want to insert data in one batch (read goes one by one):
```python with rt_2: for key in rt_1.keys(): rt_2[key] = rt_1[key] ```Transfer data from one user to another:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) for key in rt_1['arrrlo'].keys(): rt_1['edi:' + key] = rt_1['arrrlo:' + key] ```Delete user from database:
```python rt_1 = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) with rt_1: for key in rt_1['arrrlo'].keys(): del rt_1['arrrlo:' + key] ```Initially the data from yaml file transferes from file to memory.
From there every read, write or delete runs until the sync() method
is called. Then the data from memory is transfered to yaml file.
sync() method could be called using context manager or manually.
Very handy when using in docker containers.
```python from db_transfer import Transfer, sent_env os.environ['YAML_FILE_PATH'] = '/path/to/yaml/file.yaml' @sent_env('yaml', 'FILE_LOCAL', 'YAML_FILE_PATH') class YamlFileTransfer(Transfer): def __init__(self, prefix=None, namespace=None): super().__init__(prefix=str(prefix), namespace=namespace, adapter_name='yaml') ```Data could be written using context manager or sync() method.
```python yt = YamlFileTransfer(prefix='my_prefix', namespace='my_namespace', yaml_file_path='/path/') with yt: yt['my_key_1'] = 'some_string' yt['my_key_2'] = 'some_string' yt.sync() with yt: del yt['my_key_1'] del yt['my_key_2'] yt.sync() ```Backup user data from Redis to yaml file:
```python rt = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix', namespace='my_namespace', yaml_file_path='/path/') for key in rt['arrrlo'].keys(): yt['arrrlo:' + key] = rt['arrrlo:' + key] # or (depends on how you use prefix and namespace): rt = RedisTransfer(prefix='users', namespace='arrrlo', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='users', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt[key] # or: rt = RedisTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt[key] # or: rt = RedisTransfer(prefix='my_prefix', namespace='my_namespace', host='localhost', port=6379, db=0) yt = YamlFileTransfer(prefix='my_prefix:my_namespace', namespace='arrrlo', yaml_file_path='/path/') for key in rt.keys(): yt[key] = rt['arrrlo:' + key] ``` %prep %autosetup -n DB Transfer-0.5.6 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-DB-Transfer -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Fri Jun 09 2023 Python_Bot