Name | django-cache-pydantic JSON |
Version |
0.0.4
JSON |
| download |
home_page | |
Summary | Django application to integrate pydantic models into django cache with an orm interface. |
upload_time | 2024-03-15 15:08:55 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.8 |
license | MIT |
keywords |
cache
django
pydantic
orm
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
Django Cache Pydantic
=========================
Django Cache Pydantic is a minimal wrapper around django cache framework which allows you
to create pydantic instances directly inside your django project cache and retrieve them
using a similar interface like django orm.
Status
------
.. image:: https://github.com/bindruid/django-cache-pydantic/workflows/Test/badge.svg?branch=master
:target: https://github.com/bindruid/django-cache-pydantic/actions
.. image:: https://img.shields.io/pypi/v/django-cache-pydantic.svg
:target: https://pypi.python.org/pypi/django-cache-pydantic
.. image:: https://img.shields.io/pypi/pyversions/django-cache-pydantic.svg
:target: https://pypi.org/project/django-cache-pydantic
.. image:: https://img.shields.io/pypi/djversions/django-cache-pydantic.svg
:target: https://pypi.org/project/django-cache-pydantic/
Dependencies
------------
- Pydantic >= 2.6
- Django >= 3.2
Install
-------
.. code-block:: bash
pip install django-cache-pydantic
Usage
-----
1. Edit settings.py and add `django_cache_pydantic` to your `INSTALLED_APPS` (also config `CACHES` setting).
2. Inherit your pydantic model from `PydanticCachedModel`.
.. code-block:: python
from pydantic import Field, Optional
from datetime import datetime
from django_cache_pydantic import PydanticCachedModel
class Person(PydanticCachedModel):
national_id: str = Field(max_length=10, pattern=r'^\d*$')
first_name: Optional[str] = None
last_name: Optional[str] = None
mobile_number: str = Field(max_length=11, pattern=r'^\d*$')
created_at: datetime = Field(default_factory=lambda: datetime.now())
class CacheMeta:
ttl = 5 * 60
primary_key_field = 'national_id'
3. Create your model instance directly into the cache via calling to `save` method or object manager `create` method.
.. code-block:: python
# some where in your views
person = Person(national_id='123456789', mobile_number='0930444444')
person.save() # will save the instance into project default cache
.. code-block:: python
# some where in your views
Person.objects.create(national_id='123456789', mobile_number='0930444444') # will save the instance into project default cache
4. Retrieve your model instance from the cache via calling to object manager `get` method.
.. code-block:: python
# some where in your views
person = Person.objects.get(pk='123456789')
if person is not None:
# do some stuff
Cache pydantic meta class
---------------------------
- You can control cache pydantic models behavior using a custom meta class called `CacheMeta`.
.. code-block:: python
class CacheMeta:
cache_backend: str # refers to a predefined cache settings
ttl: int # default timeout for instance to live in cache
primary_key_field: str # could be set to be used as cache key
verbose: str # verbose name of base model
Cache pydantic Project Settings
----------------------------------
- Default cache to save pydantic models into.
.. code-block:: python
CACHE_PYDANTIC_DEFAULT_CACHE
- Default time to live of the pydantic cached models.
.. code-block:: python
CACHE_PYDANTIC_DEFAULT_TTL
Raw data
{
"_id": null,
"home_page": "",
"name": "django-cache-pydantic",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Ali Abharya <abharya.dev@gmail.com>",
"keywords": "cache,django,pydantic,orm",
"author": "",
"author_email": "Ali Abharya <abharya.dev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/6f/55/87dc6f96e00ab3dfe4f8954565bad0bb7f3bee9afefc70fca061088049a7/django-cache-pydantic-0.0.4.tar.gz",
"platform": null,
"description": "Django Cache Pydantic\n=========================\n\nDjango Cache Pydantic is a minimal wrapper around django cache framework which allows you\nto create pydantic instances directly inside your django project cache and retrieve them\nusing a similar interface like django orm.\n\nStatus\n------\n\n.. image:: https://github.com/bindruid/django-cache-pydantic/workflows/Test/badge.svg?branch=master\n :target: https://github.com/bindruid/django-cache-pydantic/actions\n\n.. image:: https://img.shields.io/pypi/v/django-cache-pydantic.svg\n :target: https://pypi.python.org/pypi/django-cache-pydantic\n\n.. image:: https://img.shields.io/pypi/pyversions/django-cache-pydantic.svg\n :target: https://pypi.org/project/django-cache-pydantic\n\n.. image:: https://img.shields.io/pypi/djversions/django-cache-pydantic.svg\n :target: https://pypi.org/project/django-cache-pydantic/\n\nDependencies\n------------\n\n- Pydantic >= 2.6\n- Django >= 3.2\n\nInstall\n-------\n\n.. code-block:: bash\n\n pip install django-cache-pydantic\n\nUsage\n-----\n\n1. Edit settings.py and add `django_cache_pydantic` to your `INSTALLED_APPS` (also config `CACHES` setting).\n\n2. Inherit your pydantic model from `PydanticCachedModel`.\n\n.. code-block:: python\n\n from pydantic import Field, Optional\n from datetime import datetime\n from django_cache_pydantic import PydanticCachedModel\n\n\n class Person(PydanticCachedModel):\n national_id: str = Field(max_length=10, pattern=r'^\\d*$')\n first_name: Optional[str] = None\n last_name: Optional[str] = None\n mobile_number: str = Field(max_length=11, pattern=r'^\\d*$')\n created_at: datetime = Field(default_factory=lambda: datetime.now())\n\n class CacheMeta:\n ttl = 5 * 60\n primary_key_field = 'national_id'\n\n3. Create your model instance directly into the cache via calling to `save` method or object manager `create` method.\n\n.. code-block:: python\n\n # some where in your views\n person = Person(national_id='123456789', mobile_number='0930444444')\n person.save() # will save the instance into project default cache\n\n.. code-block:: python\n\n # some where in your views\n Person.objects.create(national_id='123456789', mobile_number='0930444444') # will save the instance into project default cache\n\n4. Retrieve your model instance from the cache via calling to object manager `get` method.\n\n.. code-block:: python\n\n # some where in your views\n person = Person.objects.get(pk='123456789')\n if person is not None:\n # do some stuff\n\nCache pydantic meta class\n---------------------------\n\n- You can control cache pydantic models behavior using a custom meta class called `CacheMeta`.\n\n.. code-block:: python\n\n class CacheMeta:\n cache_backend: str # refers to a predefined cache settings\n ttl: int # default timeout for instance to live in cache\n primary_key_field: str # could be set to be used as cache key\n verbose: str # verbose name of base model\n\nCache pydantic Project Settings\n----------------------------------\n\n- Default cache to save pydantic models into.\n\n.. code-block:: python\n\n CACHE_PYDANTIC_DEFAULT_CACHE\n\n- Default time to live of the pydantic cached models.\n\n.. code-block:: python\n\n CACHE_PYDANTIC_DEFAULT_TTL\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django application to integrate pydantic models into django cache with an orm interface.",
"version": "0.0.4",
"project_urls": {
"Changelog": "https://github.com/bindruid/django-cache-pydantic/blob/master/CHANGELOG.rst",
"Repository": "https://github.com/bindruid/django-cache-pydantic"
},
"split_keywords": [
"cache",
"django",
"pydantic",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c3446c8c43ad96af69643b76f67a2d5914088d8e880f7a3c22731eadcc2c9804",
"md5": "a821e3d51e7ddb5c844fc260798f44f9",
"sha256": "455dae1216c3280b681bf659c36b91bc5cc8fae835073bf660d6a0a5d0be5573"
},
"downloads": -1,
"filename": "django_cache_pydantic-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a821e3d51e7ddb5c844fc260798f44f9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7374,
"upload_time": "2024-03-15T15:08:52",
"upload_time_iso_8601": "2024-03-15T15:08:52.571070Z",
"url": "https://files.pythonhosted.org/packages/c3/44/6c8c43ad96af69643b76f67a2d5914088d8e880f7a3c22731eadcc2c9804/django_cache_pydantic-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6f5587dc6f96e00ab3dfe4f8954565bad0bb7f3bee9afefc70fca061088049a7",
"md5": "99bfb787fc11f9c3703a7380bf02b4d3",
"sha256": "0136cce4f6756942ad31ab283c2b98829043e30368540473f368f45be3d4545f"
},
"downloads": -1,
"filename": "django-cache-pydantic-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "99bfb787fc11f9c3703a7380bf02b4d3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7269,
"upload_time": "2024-03-15T15:08:55",
"upload_time_iso_8601": "2024-03-15T15:08:55.466126Z",
"url": "https://files.pythonhosted.org/packages/6f/55/87dc6f96e00ab3dfe4f8954565bad0bb7f3bee9afefc70fca061088049a7/django-cache-pydantic-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-15 15:08:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bindruid",
"github_project": "django-cache-pydantic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-cache-pydantic"
}