Traducteur is the middle man to handle your basic data needs.
Project description
Traducteur
Traducteur is a database model manager and task sheduler which aims to make developing basic app with database models and tasks faster and easier.
Requirements
python ^3.8pydantic ^1.10.4
Optional
For mongo db:
pymongo ^4.3.3
For task queueing or redis model management:
redis-py ^4.4.2
Installation
Base install:
pip install traducteur
Install with extras:
pip install "traducteur[tasks]"
This example will install traducteur and all the packages you need to use traducteur tasks.
optional extras:
- sql
- nosql
- caching
- mongo
- tasks
- all
The idea
Context managers
with BaseContext(connection_string) as db:
return db.get()
Model managers
Model managers use context managers
manager = BaseModelManager(connection_string)
result = manager.get(example_id)
result = manager.delete(example_id)
Models
Models use model managers
class User(BaseDatabaseModel):
username: str
fname: str
lname: str
email: str
user = User(
username='johndoe',
fname='John',
lname='Doe',
email='john.doe@mail.com'
)
'''
Easy create, save, update and delete
'''
user = User(
username='johndoe',
fname='John',
lname='Doe',
email='john.doe@mail.com'
)
# saving the model
user = user.save()
# saving also updates the model
user.lname = 'Joe'
user = user.save()
# getting a model by its ID from the database
user = User.get(user_id)
# deleting a model from the database
deleted_user = user.delete()
Tasks
Tasks use models
# in a program
def my_func(a: int, b: int) -> int:
return a + b
task = BaseTask(action=my_func)
task.queue(a=8, b=3)
###############
# in a worker #
task.digest() #
###############
# some time later
result = task.result()
Chain tasks
Tasks can be chained together for larger workloads
def double(number: int):
return {
'number': number * 2
}
# make tasks
one = BaseTask(action=double)
two = BaseTask(action=double)
three = BaseTask(action=double)
# chain tasks
two.set_parent(one)
three.set_parent(two)
# queue parent task
one.queue(number=2)
###############
# in a worker #
one.digest() #
###############
# some time later
result = one.result()
assert result == 8, "Should be 8 as 2*2*2 == 8"
Available functionality
Context managers
- MongoContext
- SQLite3Context
Model managers
- MongoModelManager
- SQLModelManager
- SQLQueryBuilder
Query filters
- Datetime filter
- Number filter
- String filter
Models
- BaseMongoModel
- BaseRedisModel
- BaseSQLModel
Tasks
- RedisTask
Todo / in progress
Tasks
- Chain tasks
- Redis
- Mongo
- SQL
- Task worker
- Single Process
- Multi Process
- RabbitMQ task
Tests
Tests can be found in the test folder. They use pythons unittest and can be run with:
python3 -m unittest path/to/test.py
Tests get automatically run after each push.
Available tests
- Mongo model
- Mongo sorting
- Redis task
- Basic functions
- Chaining
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file traducteur-0.4.4.tar.gz.
File metadata
- Download URL: traducteur-0.4.4.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c2be37f25a29c362c35cf8cae8892fd2e7175a37aa4d8beae614e9a8c68e7e7
|
|
| MD5 |
48a085b34095ae0c0fa0d7bc5b7d7c48
|
|
| BLAKE2b-256 |
1d056c9e41e082165b8353fbb7ff360b5efe7f7effd7c9fac4e1c8424fb70c75
|
File details
Details for the file traducteur-0.4.4-py3-none-any.whl.
File metadata
- Download URL: traducteur-0.4.4-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d63f239f67329f2e60662a642ea13facdeba2370537fa6066986a89fecc343dd
|
|
| MD5 |
6bbff72dd0c90b150c64a27cc44a74a0
|
|
| BLAKE2b-256 |
6eb82bdc4ad8e87c28d84d92e6210d401bc35be0bd7ec200d6896851a92f0900
|