AnyAPI is a library that helps you to write any API wrapper with ease and in pythonic way.

Overview

AnyAPI

Travis (.org) Code Climate maintainability Code Climate coverage PyPI - Downloads PyPI - Python Version

AnyAPI is a library that helps you to write any API wrappers with ease and in pythonic way.

Features

  • Have better looking code using dynamic method calls.
  • Filters to help you to modify request, raise errors or log requests instead of writing functions everywhere.
  • Scoped calls to raise errors and take action if necessary.
  • Automatic retrying if the condition met with what you passed.
  • Built-in rate limit proxy changer. (you can write your own proxy handler)
  • Since it is built on top of requests anything compatible with it is compatible with AnyAPI.

But most importantly in AnyAPI almost everything is modular!


Examples

Making GET request to https://httpbin.org/anything/endpoint

from anyapi import AnyAPI


base_url = 'https://httpbin.org'
api = AnyAPI(base_url)

api.anything.endpoint.GET()

As you can see dots are pretended as slash and at the end you should put dot and HTTP method you want to use in capital letters.


Setting header before every request

import datetime
from anyapi import AnyAPI


def set_date_as_header(kwargs):
    now = datetime.datetime.now()
    kwargs['headers'].update({'date': now.strftime('%B %d %Y')})

    return kwargs

api = AnyAPI('https://httpbin.org')
api._filter_request.append(set_date_as_header)

print(api.anything.endpoint.GET().json())
# output
{
   'args': {},
   'data': '',
   'files': {},
   'form': {},
   'headers': {
      'Accept-Encoding': 'identity',
      'Connection': 'close',
      'Date': 'January 16 2019',
      'Host': 'httpbin.org'
   },
   'json': None,
   'method': 'GET',
   'origin': 'XX.XX.XX.XX',
   'url': 'https://httpbin.org/anything/endpoint'
}

As you can see filter worked as expected and set Date header.


Changing proxy automatically after they reach their rate limit

from anyapi import AnyAPI
from anyapi.proxy_handlers import RateLimitProxy

proxy_configuration = {
  'default': proxy0,
  'proxies': [proxy0, proxy1, proxy2,....], # don't forget to add default proxy!
  'paths': {
    '/anything': rate_limit0,
    '/anything/endpoint': rate_limit1
  }
}

api = AnyAPI('https://httpbin.org', proxy_configuration=proxy_configuration, proxy_handler=RateLimitProxy)

for i in range(10):
  print(api.anything.endpoint.GET().json())

If you check output of the all them you can see proxy changes when it reaches limit.

This library is not a new thing

There is a lot of libraries you can find out there for example Uplink, Hammock and many more...


Installation

Library on PyPI so just run

pip install anyapi

To learn more about AnyAPI check wiki page

You might also like...
This an API wrapper library for the OpenSea API written in Python 3.

OpenSea NFT API Python 3 wrapper This an API wrapper library for the OpenSea API written in Python 3. The library provides a simplified interface to f

A custom Discord Rich Presence to display when you're studying so you're stupid friends won't disturb you when you're studying.

Studying RPC Description A custom Discord Rich Presence to display when you're studying so you're stupid friends won't disturb you when you're studyin

aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in a future time.

aws-lambda-scheduler aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in the future. This functionality is achieved by dyn

SmsSender v3.0.0 - the script is designed to send free SMS to any number and with any text.

SmsSender v3.0.0 - скрипт предназначен для бесплатной отправки SMS на любой номер и с любым текстом. Возможны небольшие баги, в скором времени исправл

An instagram bot developed in Python with Selenium that helps you get more Instagram followers.

instabot An instagram bot developed in Python with Selenium that helps you get more Instagram followers. Install You’ll need to have: Python Selenium

This solution helps you deploy Data Lake Infrastructure on AWS using CDK Pipelines.
This solution helps you deploy Data Lake Infrastructure on AWS using CDK Pipelines.

CDK Pipelines for Data Lake Infrastructure Deployment This solution helps you deploy data lake infrastructure on AWS using CDK Pipelines. This is base

This is a simple grabber written in Python which helps you to grab products from Willhaben.at

Willhaben Grabber This is a simple grabber written in Python which helps you to grab products from Willhaben.at General info The tool generates a sear

A chatbot that helps you set price alerts for your amazon products.
A chatbot that helps you set price alerts for your amazon products.

Amazon Price Alert Bot Description A Telegram chatbot that helps you set price alerts for amazon products. The bot checks the price of your watchliste

SongFinder Bot helps you to find song name by recognising via voice note or instagram reels shared link.

SongFinder V1.1 SongFinder to detect songs name by just sending voice note or instagram reels links to your telegram bot. FFMPEG must be installed on

Comments
  • Question: dynamic header injection

    Question: dynamic header injection

    Hey thanks for the library, looks handy but want to clarify a point before I try to implement something.

    Right now I'm using nginx as a non secure to secure API bridge, that is to say, requests originating from localhost can hit nginx and a python script will go and get an oauth2 bearer token and inject it into the header so what is an unauthenticated API call can be proxied to a secure endpoint.

    Is that possible using this library? I'd like to take nginx out of the equation if I'm already using python to monitor the bearer token and expiry and subsequent refresh and injection of the header into the nginx.conf file.

    opened by danielloader 6
Releases(v1.1.701)
Owner
Fatih Kilic
first-year student & hobbyist
Fatih Kilic
A simple Telegram bot that analyses a given word, built with python-telegram-bot

Telegram Word Bot A simple Telegram bot that analyses a given word, built with python-telegram-bot. The bot is fairly useless - unless you often need

Chris N 2 Jul 14, 2022
A bot i made for a dead com server lol it gets updated daily etc

6ix-Bot-Source A bot i made for a dead com server lol it gets updated daily etc For The UserAgent CMD https://developers.whatismybrowser.com/ thats a

Swiper 9 Mar 10, 2022
A simple test repo created following docker docs.

docker_sampleRepo A simple test repo created following docker docs. Link to docs: https://docs.docker.com/language/python/develop/ Other links: https:

Suraj Verma 2 Sep 16, 2022
The Best Multipurpose Discord Bot!

Polsu The Best Multipurpose Discord Bot! • Introduction • Screenshots • Setup • License Introduction Polsu is a Multipurpose Discord Bot. Polsu has a

Polsulpicien 1 Nov 09, 2021
The most fresh and updateable Telegram userbot. By one of the most active contibutors to GeekTG

Installation Script installation: Simply run this command out of root: . (wget -qO- http://gg.gg/get_hikka) Manual installation: apt update && apt in

Dan Gazizullin 150 Jan 04, 2023
Um bot simples para seguir as pessoas

Um bot simples para seguir pessoas no instagram, criado apeanas para testes. Utilizando o framework "Selenium", criei um bot para entrar em uma conta

Mobben 1 Nov 05, 2021
Simple Discord bot for the Collectez community.

Harvey - Discord Bot Simple Discord bot for the Collectez community. Features Ping the current status of Collectez's Teztools node. Steal emojis from

delintkhaum 1 Dec 26, 2021
🚀 A fast, flexible and lightweight Discord API wrapper for Python.

Krema A fast, flexible and lightweight Discord API wrapper for Python. Installation Unikorn unikorn add kremayard krema -no-confirmation Pip pip insta

Krema 20 Sep 04, 2022
a public repository helping ML/DL engineers and DS to beautify the notebook with minimal coding.

ml-helper-functions a public repository helping ML/DL engineers and DS to beautify the notebook with minimal coding.

Jesal Patel 4 Jun 24, 2021
GitHub Activity Generator - A script that helps you instantly generate a beautiful GitHub Contributions Graph for the last year.

GitHub Activity Generator A script that helps you instantly generate a beautiful GitHub Contributions Graph for the last year. Before 😐 😶 😒 After ?

1 Dec 30, 2021
A Telegram bot for personal utilities

Aqua Aqua is a Telegram bot for personal utilities. Installation Prerequisites: Install Poetry for managing dependencies and fork/clone the repository

Guilherme Vasconcelos 2 Mar 30, 2022
Moon-TikTok-Checker - A TikTok Username checking tool that probably 3/4 people use to get rare usernames

Moon Checker (educational Purposes Only) What Is Moon Checker? This is a TikTok

glide 4 Nov 30, 2022
🔎 Hunt down social media accounts by username across social networks

Hunt down social media accounts by username across social networks Installation | Usage | Docker Notes | Contributing Installation # clone the repo $

Sherlock 38.2k Jan 01, 2023
Download song lyrics and metadata from Genius.com 🎶🎤

LyricsGenius: a Python client for the Genius.com API lyricsgenius provides a simple interface to the song, artist, and lyrics data stored on Genius.co

John W. Miller 738 Jan 04, 2023
A Telegram Message Manager Bot by @AbirHasan2005

Messages-Manager-Bot A Telegram Message Manager Bot by @AbirHasan2005. This Bot can delete specific type of messages from Group. I specially use for @

Abir Hasan 32 Nov 12, 2022
Python SDK for 42DI

42di Python SDK Install pip install git+https://github.com/42di/python-sdk import import di #42di import pandas_datareader as pdr Init SDK project =

42DI 2 Nov 03, 2021
A Bot to Track Kernel Upstreams from kernel.org and Post it on Telegram Channel

Channel Kernel Tracker is the channel where the bot will be sending the updates in. Introduction This is a Telegram Bot to Track Kernel Upstreams kern

Kartikeya Hegde 3 Oct 05, 2021
Video Stream: an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat 🧪 Get SESSION_NAME from below: Pyrogram

Jonathan 6 Feb 08, 2022
Fully undetected auto skillcheck hack for dead by daylight that works decently well

Auto-skillcheck was made by Love ❌ code ✅ ❔ ・How to use Start off by installing python ofc Open cmd in the same directory and type pip install -r requ

Rdimo 10 Aug 13, 2022
Cdk-python-crud-app - CDK Python CRUD App

Welcome to your CDK Python project! You should explore the contents of this proj

Shapon Sheikh 1 Jan 12, 2022