https://github.com/tobetek/servus
A wrapper for the aiohttp library for making asynchronous web requests in Python
https://github.com/tobetek/servus
aiohttp async asyncio python web
Last synced: 4 months ago
JSON representation
A wrapper for the aiohttp library for making asynchronous web requests in Python
- Host: GitHub
- URL: https://github.com/tobetek/servus
- Owner: TobeTek
- License: apache-2.0
- Created: 2022-04-15T19:28:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-11T23:40:06.000Z (almost 4 years ago)
- Last Synced: 2025-10-27T15:27:29.396Z (8 months ago)
- Topics: aiohttp, async, asyncio, python, web
- Language: Python
- Homepage: https://tobetek.github.io/servus
- Size: 424 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Servus
[](https://badge.fury.io/py/servus)
[](https://pypi.org/project/servus/1.0.0/)
[](https://github.com/PyCQA/bandit)
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:
```py
import servus
import aiohttp
import asyncio
async def main():
# Create a new session
my_session = servus.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(my_session, "http://httpbin.org/get")
print(response.json) # (dict)
print(response.response) # (aiohttp.ClientResponse)
# Remeber to close the session!
my_session.close()
asyncio.run(main())
```
`servus` also has inbuilt support for working with Discord bots.
Example Usage:
```py
import discord
from discord.ext import commands
import asyncio
import servus
from servus.discord_utils import create_requests_client
MY_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(create_requests_client(bot))
# Run the bot
bot.run(MY_TOKEN)
```