Skip to main content

Traducteur is the middle man to handle data

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.8
  • pydantic ^1.10.4

For mongo db management:

  • pymongo ^4.3.3

For task queueing or redis model management:

  • redis-py ^4.4.2

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.find_one(query)
result = manager.delete(query)

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

Models

  • BaseMongoModel
  • BaseRedisModel

Tasks

  • RedisTask

Todo / in progress

Models

  • SQLite support

Tasks

  • Chain tasks
    • Redis
    • Mongo
    • SQL
  • Task worker
    • Single Process
    • Multi Process
  • RabbitMQ task

Managers

  • SQLite manager

Tests

Tests can be found in the tests folder. They use pythons unittest and can be run with:

python3 -m unittest path/to/test.py

Available tests

  • Redis task
    • Basic functions
    • Chaining

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

traducteur-0.3.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

traducteur-0.3.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file traducteur-0.3.0.tar.gz.

File metadata

  • Download URL: traducteur-0.3.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.8.8 Windows/10

File hashes

Hashes for traducteur-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6a797854485273fe263989be0387a1bb29e0d5e91b29fabda1a0083f8e021b24
MD5 a8211d6e8fed72bea10b848eed580a93
BLAKE2b-256 bd60a690bd4e7b93adfdf4df2abed02d8f3731e4cde2d59f3b250a5927ac1012

See more details on using hashes here.

File details

Details for the file traducteur-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: traducteur-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.8.8 Windows/10

File hashes

Hashes for traducteur-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d789f5738bc94e45a0d2551638450500060c33147a324558e6a66f2871b040f5
MD5 c3712796fca225b02562c8eedfddda1e
BLAKE2b-256 fdc7859c58af6b9eb344c78a036c8778fae8118c0361d87a2ea74c3762516669

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page