Auto APIs for lazy people.
Project description
IDRC
I Don't Really Care (IDRC): Auto APIs for lazy people
Table of Contents
Installation
IDRC can be installed via pip
like so:
pip3 install idrc
Usage
IDRC can integrate with any function. For example:
from idrc import idrc
# Initialize the idrc class
api = idrc(verbose=True)
# Simulate a weather database
weather_data = {
"New York": {"temperature": 25, "condition": "Sunny"},
"Los Angeles": {"temperature": 30, "condition": "Cloudy"},
"Chicago": {"temperature": 18, "condition": "Rainy"}
}
# Define a weather forecast function
def get_weather(city: str) -> dict:
forecast = weather_data.get(city, None)
if forecast:
return forecast
else:
return api.ecode(404, 'City not found')
# Register the function as an API endpoint
api.define(get_weather, methods=['GET'])
# Run the idrc API
if __name__ == '__main__':
api.run(host='0.0.0.0', port=5000, debug=True)
The define
function in the idrc
library generated the api.
The Flask equivalent of the code above is:
from flask import Flask, request, jsonify
# Initialize the Flask app
app = Flask(__name__)
# Simulate a weather database
weather_data = {
"New York": {"temperature": 25, "condition": "Sunny"},
"Los Angeles": {"temperature": 30, "condition": "Cloudy"},
"Chicago": {"temperature": 18, "condition": "Rainy"}
}
# Define a weather forecast function
@app.route('/api/v1/get_weather', methods=['GET'])
def get_weather():
city = request.args.get('city')
if not city:
return jsonify({"error": "City parameter is required"}), 400
forecast = weather_data.get(city)
if forecast:
return jsonify(forecast)
else:
return jsonify({"error": "City not found"}),404
# Run the Flask app
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
IDRC condensed 27 lines of code into 25 lines of code, with much less typing overall.
IDRC vs Flask
Advantages of IDRC
- Rapid API development
- Very Simple
- Built-in error handling
- Lightweight wrapper of Flask
- Pretty terminal output
Advantages of Flask
- Mature framework
- Large community
- Flexible and extensible
- Extensive documentation
- Stack traces
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
idrc-1.3.2.tar.gz
(10.7 kB
view details)
Built Distribution
idrc-1.3.2-py3-none-any.whl
(11.2 kB
view details)
File details
Details for the file idrc-1.3.2.tar.gz
.
File metadata
- Download URL: idrc-1.3.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff003a58ce414caa25b1f2dc09f89f60818054bcb7e41efb48e04989a6958232 |
|
MD5 | f791f12b99a41e5bbcdc4234706aa4c7 |
|
BLAKE2b-256 | 94c09e0f1999a11603175671ac07528299d7f81b854deb5e1c0f000eebd9b461 |
Provenance
File details
Details for the file idrc-1.3.2-py3-none-any.whl
.
File metadata
- Download URL: idrc-1.3.2-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950caf61146f0ae3f181841896e352851d64689bd9cd99ff8335da210f218a80 |
|
MD5 | c907ae89dae75b9e1f657272609b44b4 |
|
BLAKE2b-256 | 6b18e4c7413700212b64ffc7862e2c6f2cfcef6d24646bf8eddfb37f0a56b956 |