Services
Services is a simple Django app to consume json services in a simple way. You can make requests directly, async or recursive using failover services automatically while the services return errors. Example:
from services.models import Service
service_example = Service(name='simple_service', method='get', url='http://example.com/?query_param=<data>')
url_data = {'<data>': 'example_data'}
service_response = service_example.request(url_data=get_data)
# By default http responses higher than 400 are not consider as successful,
# this can we tweaked in the service instance by adding codes to accepted_codes or rejected_codes.
if service_response['success']:
response_content = service_response['content'] # content is a dict
print(response_content)
Post example:
from services.models import Service
service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "<content_type>"}', parameters= '{"query_param": "<data>"}')
get_data = {'<data>': 'example_data'}
header_data = {'<content_type>': 'application/json'}
service_response = service_example.request(get_data=get_data, header_data=header_data)
if service_response['success']:
response_content = service_response['content'] # content is a dict
print(response_content)
Or simpler:
from services.models import Service
# This headers will be use for every request to this service
service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "application/json"}')
# parameters will be put directly to the body of the post request to the service
parameters = {'query_param': 'example_data'}
service_response = service_example.request(parameters=parameters)
if service_response['success']:
response_content = service_response['content'] # content is a dict
print(response_content)
You can also configure failover services, so if the primary service return some error code (for now >= 400) the failover/s will we call one by one untill some of them return a non error code:
from services.models import Service, ServiceFailover
service_01 = Service(name='registration_precheck', method='get', url='http://example_01.com/?query_param=<data>').save()
service_02 = Service(name='registration_precheck', method='get', url='http://example_02.com/?query_param=<data>').save()
service_03 = Service(name='registration_precheck', method='get', url='http://example_03.com/?query_param=<data>').save()
ServiceFailover(service=service_01, failover=service_02, order=1).save()
ServiceFailover(service=service_01, failover=service_03, order=2).save()
url_data = {'<data>': 'example_data'}
# Now if service_01 fails service_02 will be execute with the same context data,
# the same for service_03 if service_02 fails in this call.
service_response = service_example.request_recursive(url_data=get_data)
if service_response['success']:
response_content = service_response['content'] # content is a dict
print(response_content)
If you want to publish information to some service but you don’t want to wait you can make async request:
from services.models import Service
service_example = Service(name='simple_service', method='post', url='http://example.com/', headers='{"Content-Type": "application/json"}')
parameters = {'query_param': 'example_data'}
# max_retry is the amount of retries do you want to execute the request while the answer is a error (0 if you want to retry "forever").
# retry_interval is the amount of seconds you want to wait between retries.
service_example.request_async(max_retry=10, retry_interval=1, parameters=parameters)
Quick start
Run pip install django-easy-services
Add “services” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'services', ]Run python manage.py migrate to create the services models.
Start the development server and visit http://127.0.0.1:8000/admin/services to create a service (you’ll need the Admin app enabled).
Metadata
Release files for django-easy-services 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-easy-services-0.3.tar.gz | 7.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_easy_services-0.3-py3.8.egg | Legacy Egg format | - | - | Details |
Total release size: 22.7 kB
Release files / django-easy-services-0.3.tar.gz
| Download URL | django-easy-services-0.3.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a6fcbd99906393d20a89decfe3ec90b4549e4a8138407260e6479459c8d6007
|
|
BLAKE2b-256 checksum How to use checksums |
d43533876b31fcd79d07dda2ab28cf6288115b84757f298766610eaf03f34705
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
|
Release files / django_easy_services-0.3-py3.8.egg
| Download URL | django_easy_services-0.3-py3.8.egg |
|---|---|
| Size | 15.4 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
55d58251df1e84d8c79a5da6700a9eb548bd15b9a3d90f88af80d9ab1d5ef2d3
|
|
BLAKE2b-256 checksum How to use checksums |
d0d98ecaf0647940d6144615723c8532a5cdef083fdb0cd7d191dc6b843e0204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
|
Security for django-easy-services 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.