Chanina is a Python application to automate and orchestrate Playwright sessions using a Celery-based task system.
Project description
Chanina
Chanina is a Python application to automate and orchestrate Playwright sessions using a Celery-based task system. It provides a workflow manager, a shared context between tasks, and utilities to interact programmatically with web pages. A CLI is also available to run workflows or tasks from the terminal.
This aims at transforming what is often a tedious and imprecise process, to a more scalable, developper friendly and robust part of your tests suite.
Features
- Playwright session management:
WorkerSessionshares the Playwright context, pages, and utility tools among all tasks within the same worker. - Celery task system: create, register, and execute reusable tasks using the
@featuredecorator. - Complex workflows: support for chains and groups of tasks, with sequences managed automatically.
- Smart tools for Playwright: navigate, inspect, interact and wait modules gathers methods.
- CLI: run workflows or tasks from the terminal.
- Isolated browser profiles: manage profiles to prevent conflicts between workers and the main playwright process.
Installation
git clone <REPO_URL>
cd <REPO_NAME>
poetry install
Running Celery Workers
celery -A sub_module.module:celery_app worker --loglevel=info
Usage
Register tasks with Celery
@app.feature("my_task")
def do_something(session: WorkerSession, args: dict):
# session is the shared WorkerSession containing the current page and utilities
page = session.new_page()
session.goto(page, "https://example.com")
session.close_page(page)
The first parameter of the feature's function always is the WorkerSession object. !! Except when making a 'bind=True' parameter for the task, in which case the first parameter is the instance of the class.
Create and execute workflows
A workflow is a json file in which you can construct a sequence of tasks and specifies arguments. The workflow has two main keys : 'steps' and 'instance'.
-
The 'steps' section are the features you want to use in your workflow ordered and with the arguments specified.
-
The 'instancce' section is where you can specified if a 'step' defined in the other section needs multiple instances.
If you have a 'extract_html' feature, and you add it in your workflow, you can add as much instance of it as you need page to extract_html from, passing the page url in the 'args' key.
- Every step has a 'flow_type' argument, that can be 'chain' or 'group', and will determine the kind of celery task it will be.
NOTE
The sequence is built in the order of the steps in the file. 'group' task will be run FIRST and are non blocking for the rest of the sequence. In the workflow example underneath, we can imagine that the flow_type 'group' of the task 'save_to_mongodb' is because the task is a while loop running in parallel which saves in the db what the 'check_post' task is parsing.
Here is an example of a workflow file :
{
"steps": [
{
"identifier": "login_to_platform",
"args": {"password": "", "username": "Joseph S"},
"flow_type": "chain"
},
{
"identifier": "check_post",
"flow_type": "chain"
},
{
"identifier": "save_in_mongodb",
"args": {"user": "mongo_user", "pw": "", "host": "localhost", "port": 27017},
"flow_type": "group"
}
],
"instances": {
"check_post": [
{
"args": {
"post_url": "https://instagram.com/p/publication1"
}
},
{
"args": {
"post_url": "https://instagram.com/p/publication2"
}
},
{
"args": {
"post_url": "https://instagram.com/p/publication3"
}
}
]
}
}
Use the CLI
Tasks can be ran with the CLI, please use 'poetry run cli --help' to learn more.
$ poetry run cli login_workflow.json --app login_process.app:celery --arguments password=$PASSWORD username=$USERNAME
You can also manually run a task if your worker is still up
$ poetry run cli --task check_post --app login_process.app:celery --arguments post_url="https://www.instagram.com/p/another-publication-not-in-the-workflow"
License
For now this project has no Licence, i'm working on it.
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 chanina-0.2.0.tar.gz.
File metadata
- Download URL: chanina-0.2.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/6.14.0-33-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bcd75e7d38664061baab725f6d801ed7aef64eb7509d5293522bbe75bd9aa10
|
|
| MD5 |
d3c4b4e574f27c5d43f0e97355979d7e
|
|
| BLAKE2b-256 |
51861efe8ca4f50884d85ddde722f95c0c77fa0ee7e0a05953f3fd5f91c27ab6
|
File details
Details for the file chanina-0.2.0-py3-none-any.whl.
File metadata
- Download URL: chanina-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/6.14.0-33-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d9123ce35debe9f97f768f942711e0cc882325e37804a17f51ae93960a1f0d5
|
|
| MD5 |
5460157c850a67530b229f6becdfd52b
|
|
| BLAKE2b-256 |
540650e1f16fc990f283465c32b4f398bf987424aa300c70d9074b2658a32035
|