Skip to main content

Human-friendly wrapper around the aiohttp library for making asynchronous web requests

Project description

Servus

A wrapper for the aiohttp library for making asynchronous web requests in Python.

Trying to preserve speed and flexibility provided by aiohttp, without sacrificing the human-friendliness of requests, servus abstracts using client sessions and context managers when making asynchronous HTTP requests in Python.

Example usage:

import servus
import aiohttp
import asyncio

async def main():
	# Create a new session
	mySession = aiohttp.ClientSession()
	
	# Use Servus to send a request. 
	# Servus automatically parses and serializes the response, and returns a ready to use object
	response = await servus.get(mySession, "http://httpbin.org")
	
	print(response.response) # (aiohttp.ClientResponse )
	print(response.json) # (dict)

	# Remeber to close the session!
	mySession.close()

asyncio.run(main())

servus also has inbuilt support for working with Discord bots.

Example Usage:

import discord
from discord.ext import commands
import asyncio
import servus
from servus.discord_utils import createRequestsClient

MY_TOKEN = "<YOUR_TOKEN>"
bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"))


@bot.command()
async  def hello(ctx):
	"""Hello world, with a HTTP request!"""
	r = await servus.get(bot.session,"https://httpbin.org")
	data = r.json
	await ctx.send(f"World! {data}")

# Add the createRequestClient coroutine to `bot` async loop
bot.loop.create_task(createRequestsClient(bot))

# Run the bot
bot.run(MY_TOKEN)

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

servus-1.0.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

servus-1.0.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file servus-1.0.0.tar.gz.

File metadata

  • Download URL: servus-1.0.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.1

File hashes

Hashes for servus-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d34a94cc73fa847b62a5f2ba169ad3a2160c3e2282c6b18f0a4ab6090d6385d5
MD5 87519089c6df9107f397ec4d9862a160
BLAKE2b-256 25e53d06a5b8d4f3d8563881d70f71289671df7719ad69e7d85b68f2c93d174b

See more details on using hashes here.

File details

Details for the file servus-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: servus-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.1

File hashes

Hashes for servus-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18519d72bf4176554c5c2781832a183eb02cea2e563261ce623a809541c83f2e
MD5 ca527db75e60e5bd3fca5c7a4e7c945f
BLAKE2b-256 af912bd247a3ec535e56fccb9b8a0fb05a23f8cc548b02c6a8dbc3e0f8b9c3fc

See more details on using hashes here.

Supported by

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