Code Monkey home page Code Monkey logo

wordpress-fastapi's Introduction

Wordpress-FastApi

FastAPI To Consime woocomerce API , high performance, easy to learn, fast to code, ready for production

Installation

$ python3 -m virtualenv -p python3 .
$ source bin/activate
$ pip install -r requirements.txt

---> 100%

Create it

  • Create a file main.py with:
from fastapi import FastAPI
from woocommerce import API
import os
import json
import base64 # the easieast way to send a url as param :)

app = FastAPI()
@app.get("/wordpress/{consumerKey}/{consumerSecret}/{site}")
def  getter(consumerKey,consumerSecret,site):
	try:
		wcapi = API(
			url=base64.b64decode(site),
			consumer_key=consumerKey,
			consumer_secret=consumerSecret,
			version="wc/v3"
		)
		return {"products": wcapi.get("products").json()}
	except:
		return {"Error": " Please verify parameters"}

Note:

This is used by calling http://server:port/wordpress/consumer_key/consumer_secret/url_encoded where server = ip address ( 127.0.0.1 in dev mode ) port = fast api operating port ( 8000 by default ) consumer_key = obtained from WooCommerce API in wordpress consumer_secret = obtained from WooCommerce API in wordpress url_encoded = base64.encode(URL_TO_Wordpress)

Run it

Run the server with:

$ uvicorn main:app --reload

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [28720]
INFO:     Started server process [28722]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
About the command uvicorn main:app --reload...

The command uvicorn main:app refers to:

  • main: the file main.py (the Python "module").
  • app: the object created inside of main.py with the line app = FastAPI().
  • --reload: make the server restart after code changes. Only do this for development.

The server should reload automatically (because you added --reload to the uvicorn command above).

License

This project is licensed under the terms of the GPL license.

wordpress-fastapi's People

Contributors

darguechi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.