Skip to main content

PyForgeAPI is a fast and easy-to-use open source python library for developing RESTful APIs. It provides a clear and concise syntax for handling routes, requests, and responses, making the development of APIs faster and more efficient. With support for form parameters, body and route parameters, it is useful for handling different types of requests. Whether you are a beginner or an experienced developer, PyForgeAPI is a simple and powerful choice for creating robust and scalable APIs.

Project description

PyForgeAPI

What is it and what is it for

PyForgeAPI is a fast, very simple to use and understand open source python library for developing RESTful APIs.

Installation

pip install PyForgeAPI

Examples

Example for GET Route with Query Params and debug mode

from PyForgeAPI import Routes, Response, Request

# Debug mode is False by default
routes = Routes(debug=True)

@routes.get('/')
async def home(req: Request, res: Response):
  # Get query params age
  age = req.query['age']
  # Recovery all persons from database with this age
  res.html("<h1>Listing all persons</h1><ul><li>A Person</li></ul>").status(200).send()

routes.run(application="Person API", host="localhost", port=3000)

Example for GET Route with Params, CORS and multiple methods

from PyForgeAPI import Routes, Response, Request

routes = Routes().cors()

@routes.get('/user/:id')
@routes.post('/user/:id')
async def getUser(req: Request, res: Response):
  # get users from database
  for i in users:
    if i["id"] == req.params["id"]:
      res.json(i).send()
      return
  res.send_status(404)

routes.run(application="Person API", host="localhost", port=3000)

Example for POST Route with Body

from PyForgeAPI import Routes, Response, Request

routes = Routes()

@routes.post('/user')
async def createUser(req: Request, res: Response):
  user = req.body.json
  # Save user in database
  res.text("Created").status(201).send()

routes.run(application="Person API", host="localhost", port=3000)

Example for PUT Route with Body

from PyForgeAPI import Routes, Response, Request

routes = Routes()

@routes.put('/user')
async def createUser(req: Request, res: Response):
  user = req.body.json
  # Update user in database
  res.html('<h1>Created</h1>').status(201).send()

routes.run(application="Person API", host="localhost", port=3000)

Using modules

# chat.py
from PyForgeAPI import Request, Response, Module

chat = Module('chat', '/chat')

@chat.get('/')
async def index(req: Request, res: Response):
  res.send_status(200)

@chat.get('/chat')
async def test(req: Request, res: Response):
  res.send_status(200)
# message.py
from PyForgeAPI import Request, Response, Module

message = Module('message', '/message')

@message.get('/')
async def index(req: Request, res: Response):
  res.send_status(200)

@message.get('/message')
async def test(req: Request, res: Response):
  res.send_status(200)
# main.py
from decorators.routes import Routes

from message import message
from chat import chat

routes = Routes(debug=True).cors()

routes.bind(message)
routes.bind(chat)

routes.run(host='localhost')

See more examples in examples folder

Change Log

Version 1.4.0

ToDo

  • Automatic docs Page

Added

  • Automatic reload in development mode (EXPERIMENTAL)
  • Request method PATCH
  • More security in CORS
  • JSON Database module

Changed

  • Better params and query params recovery in routes
  • Improved route logging

Contributors

How to Contributing

Open pull request 😎

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

PyForgeAPI-1.4.0.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

PyForgeAPI-1.4.0-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file PyForgeAPI-1.4.0.tar.gz.

File metadata

  • Download URL: PyForgeAPI-1.4.0.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for PyForgeAPI-1.4.0.tar.gz
Algorithm Hash digest
SHA256 6db52664574e6b4dc19986159d3f8404e040685b1fdc95df15f4918e326a0964
MD5 e74ec2876da97a092488229a37479e9d
BLAKE2b-256 c54752a0c6d3c8814f9df7a5b556bb8bfb8b69a1698fc6e69a777406a9add516

See more details on using hashes here.

File details

Details for the file PyForgeAPI-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: PyForgeAPI-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for PyForgeAPI-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 798a88f8a6618fe0f5b79818adbbf5e26b4186661d48d6231af6565515eed522
MD5 29f7696d71130a0aa386b53dd119eb81
BLAKE2b-256 3570cc8127b17c2db596e262898e5f7da91e938746ec0a1bb14b26c9df320fe6

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