Skip to main content

A simple Django app to handle services request.

Project description

Services is a simple Django app to consume simple 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)

if service_response['success']:
    respose_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']:
    respose_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']:
    respose_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']:
    respose_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

  1. Run pip install django-easy-services

  2. Add “services” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
            ...
            'services',
    ]
  3. Run python manage.py migrate to create the services models.

  4. Start the development server and visit http://127.0.0.1:8000/admin/services to create a services (you’ll need the Admin app enabled).

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

django-easy-services-0.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

django_easy_services-0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file django-easy-services-0.2.tar.gz.

File metadata

  • Download URL: django-easy-services-0.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for django-easy-services-0.2.tar.gz
Algorithm Hash digest
SHA256 eff36f73ea5dad9ada291e04037db06326068f29fc69bbca1b13bd87af91574f
MD5 78d2a78d8e5eadd22703ec7ff9c797f3
BLAKE2b-256 f7e1d8d793469aa87110b0700555a32e07337b0efa2bed22deb230caea4a07d3

See more details on using hashes here.

File details

Details for the file django_easy_services-0.2-py3-none-any.whl.

File metadata

  • Download URL: django_easy_services-0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for django_easy_services-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9727ab9275e61ac9ef9897a3cb3370b92fa9340ad40091caa597f77ce34a534c
MD5 ffdde458fc4cdaffa4a8dc768d30ce72
BLAKE2b-256 cf1f57082d301ca7fc8209b626294492dd9aa36f881f3a499611863367d81144

See more details on using hashes here.

Supported by

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