1665721117
Chard is a simple async/await background task queue for Django. One process, no threads, no other dependencies.
It uses Django's ORM to keep track of tasks. This is a new project under active development. PRs are welcome!
pip install django-chard
First add chard
anywhere in your INSTALLED_APPS
setting and then run the migrations:
python manage.py migrate
Create a file called tasks.py
in one of your apps and define a task:
import chard
import httpx
from asgiref.sync import sync_to_async
from .models import MyModel
@chard.task
async def my_task(country_code):
url = f"https://somewhere.com/some-api.json?country_code={country_code}"
async with httpx.AsyncClient() as client:
resp = await client.get(url)
obj = resp.json()
for item in obj["items"]:
await sync_to_async(MyModel.objects.create)(
country_code=country_code,
item=item
)
To fire a task for the worker:
# Note that all arguments must be JSON serializable.
my_task.send("gb")
Run the worker process and it will watch for new pending tasks:
python manage.py chardworker
To see a full example of Chard in action:
🔗 Check the example Django project
0.2 (2022-09-16)
- Type hinting
- Return a task ID when queueing a task
- Added docs
- Tidying and bug fixes
📖 Documentation
📨 Sign up to the newsletter to get news and updates
🔗 Check the example Django project
Download Details:
Author: drpancake
Source Code: https://github.com/drpancake/chard
#python #django
1620177818
Welcome to my blog , hey everyone in this article you learn how to customize the Django app and view in the article you will know how to register and unregister models from the admin view how to add filtering how to add a custom input field, and a button that triggers an action on all objects and even how to change the look of your app and page using the Django suit package let’s get started.
#django #create super user django #customize django admin dashboard #django admin #django admin custom field display #django admin customization #django admin full customization #django admin interface #django admin register all models #django customization
1620185280
Welcome to my blog, hey everyone in this article we are going to be working with queries in Django so for any web app that you build your going to want to write a query so you can retrieve information from your database so in this article I’ll be showing you all the different ways that you can write queries and it should cover about 90% of the cases that you’ll have when you’re writing your code the other 10% depend on your specific use case you may have to get more complicated but for the most part what I cover in this article should be able to help you so let’s start with the model that I have I’ve already created it.
**Read More : **How to make Chatbot in Python.
Read More : Django Admin Full Customization step by step
let’s just get into this diagram that I made so in here:
Describe each parameter in Django querset
we’re making a simple query for the myModel table so we want to pull out all the information in the database so we have this variable which is gonna hold a return value and we have our myModel models so this is simply the myModel model name so whatever you named your model just make sure you specify that and we’re gonna access the objects attribute once we get that object’s attribute we can simply use the all method and this will return all the information in the database so we’re gonna start with all and then we will go into getting single items filtering that data and go to our command prompt.
Here and we’ll actually start making our queries from here to do this let’s just go ahead and run** Python manage.py shell** and I am in my project file so make sure you’re in there when you start and what this does is it gives us an interactive shell to actually start working with our data so this is a lot like the Python shell but because we did manage.py it allows us to do things a Django way and actually query our database now open up the command prompt and let’s go ahead and start making our first queries.
#django #django model queries #django orm #django queries #django query #model django query #model query #query with django
1665721117
Chard is a simple async/await background task queue for Django. One process, no threads, no other dependencies.
It uses Django's ORM to keep track of tasks. This is a new project under active development. PRs are welcome!
pip install django-chard
First add chard
anywhere in your INSTALLED_APPS
setting and then run the migrations:
python manage.py migrate
Create a file called tasks.py
in one of your apps and define a task:
import chard
import httpx
from asgiref.sync import sync_to_async
from .models import MyModel
@chard.task
async def my_task(country_code):
url = f"https://somewhere.com/some-api.json?country_code={country_code}"
async with httpx.AsyncClient() as client:
resp = await client.get(url)
obj = resp.json()
for item in obj["items"]:
await sync_to_async(MyModel.objects.create)(
country_code=country_code,
item=item
)
To fire a task for the worker:
# Note that all arguments must be JSON serializable.
my_task.send("gb")
Run the worker process and it will watch for new pending tasks:
python manage.py chardworker
To see a full example of Chard in action:
🔗 Check the example Django project
0.2 (2022-09-16)
- Type hinting
- Return a task ID when queueing a task
- Added docs
- Tidying and bug fixes
📖 Documentation
📨 Sign up to the newsletter to get news and updates
🔗 Check the example Django project
Download Details:
Author: drpancake
Source Code: https://github.com/drpancake/chard
#python #django
1650391200
The Ansible Jupyter Kernel adds a kernel backend for Jupyter to interface directly with Ansible and construct plays and tasks and execute them on the fly.
ansible-kernel
is available to be installed from pypi but you can also install it locally. The setup package itself will register the kernel with Jupyter
automatically.
pip install ansible-kernel
python -m ansible_kernel.install
pip install -e .
python -m ansible_kernel.install
pip install ansible-kernel
python -m ansible_kernel.install --sys-prefix
jupyter notebook
# In the notebook interface, select Ansible from the 'New' menu
docker run -p 8888:8888 benthomasson/ansible-jupyter-kernel
Then copy the URL from the output into your browser:
http://localhost:8888/?token=ABCD1234
Normally Ansible
brings together various components in different files and locations to launch a playbook and performs automation tasks. For this jupyter
interface you need to provide this information in cells by denoting what the cell contains and then finally writing your tasks that will make use of them. There are Examples available to help you, in this section we'll go over the currently supported cell types.
In order to denote what the cell contains you should prefix it with a pound/hash symbol (#) and the type as listed here as the first line as shown in the examples below.
The inventory that your tasks will use
#inventory
[all]
ahost ansible_connection=local
anotherhost examplevar=val
This represents the opening block of a typical Ansible
play
#play
name: Hello World
hosts: all
gather_facts: false
This is the default cell type if no type is given for the first line
#task
debug:
#task
shell: cat /tmp/afile
register: output
This takes an argument that represents the hostname. Variables defined in this file will be available in the tasks for that host.
#host_vars Host1
hostname: host1
This takes an argument that represents the group name. Variables defined in this file will be available in the tasks for hosts in that group.
#group_vars BranchOfficeX
gateway: 192.168.1.254
This takes an argument that represents the filename for use in later cells
#vars example_vars
message: hello vars
#play
name: hello world
hosts: localhost
gather_facts: false
vars_files:
- example_vars
This takes an argument in order to create a templated file that can be used in later cells
#template hello.j2
{{ message }}
#task
template:
src: hello.j2
dest: /tmp/hello
Provides overrides typically found in ansible.cfg
#ansible.cfg
[defaults]
host_key_checking=False
You can find various example notebooks in the repository
It's possible to use whatever python development process you feel comfortable with. The repository itself includes mechanisms for using pipenv
pipenv install
...
pipenv shell
Author: ansible
Source Code: https://github.com/ansible/ansible-jupyter-kernel
License: Apache-2.0 License
1620377063
https://www.codecheef.org/article/react-async-await-fetch-api-call-example
#react #fetch-api #async #await #async-await