All Projects → daleal → symmetric

daleal / symmetric

Licence: MIT license
A powerful tool to enable super fast module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to symmetric

asymmetric
Ridiculously fast and easy module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.
Stars: ✭ 35 (-46.15%)
Mutual labels:  openapi, pip, redoc
cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (-26.15%)
Mutual labels:  openapi, redoc
starlite
Light, Flexible and Extensible ASGI API framework
Stars: ✭ 1,525 (+2246.15%)
Mutual labels:  openapi, redoc
apiflask
A lightweight Python web API framework.
Stars: ✭ 442 (+580%)
Mutual labels:  openapi, redoc
Redoc
📘 OpenAPI/Swagger-generated API Reference Documentation
Stars: ✭ 15,935 (+24415.38%)
Mutual labels:  openapi, redoc
flaskerk
A flask extension for api doc and validation of request&response.
Stars: ✭ 24 (-63.08%)
Mutual labels:  openapi, redoc
spectree
API spec validator and OpenAPI document generator for Python web frameworks.
Stars: ✭ 190 (+192.31%)
Mutual labels:  openapi, redoc
rules poetry
Bazel rules that use Poetry for Python package management
Stars: ✭ 40 (-38.46%)
Mutual labels:  poetry, pip
Drf Yasg
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
Stars: ✭ 2,523 (+3781.54%)
Mutual labels:  openapi, redoc
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+60804.62%)
Mutual labels:  openapi, redoc
poetry-setup
Generate setup.py (setuptools) from pyproject.toml (poetry)
Stars: ✭ 44 (-32.31%)
Mutual labels:  poetry, pip
Dephell
📦 🔥 Python project management. Manage packages: convert between formats, lock, install, resolve, isolate, test, build graph, show outdated, audit. Manage venvs, build package, bump version.
Stars: ✭ 1,730 (+2561.54%)
Mutual labels:  poetry, pip
pmm
PyPi Mirror Manager
Stars: ✭ 29 (-55.38%)
Mutual labels:  pip
dotfiles
🔯 A collection of my rc files (tmux, neovim, zsh, fish, poetry, git, ...etc) and utilities that make everyday coding fun!
Stars: ✭ 23 (-64.62%)
Mutual labels:  poetry
TensorFlow-Raspberry-Pi
TensorFlow installation wheels for Raspberry Pi 32-bit OS
Stars: ✭ 18 (-72.31%)
Mutual labels:  pip
OpenAPI-Viewer
OpenApi viewer Implemented using Vue
Stars: ✭ 93 (+43.08%)
Mutual labels:  openapi
arcus.webapi
Web API development with Microsoft Azure in a breeze.
Stars: ✭ 19 (-70.77%)
Mutual labels:  openapi
pip-custom-platform
pip+wheel wrapper which allows you to choose a custom platform name for building, downloading, and installing wheels.
Stars: ✭ 50 (-23.08%)
Mutual labels:  pip
aws2openapi
Amazon Web Services API description to OpenAPI 3.0 definition
Stars: ✭ 45 (-30.77%)
Mutual labels:  openapi
MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+140%)
Mutual labels:  openapi

Symmetric

PyPI - Version PyPI - Downloads

A powerful tool to enable super fast module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.

Tests Workflow Linters Workflow

Disclaimer

symmetric is no longer being maintained. But don't worry! Its spiritual successor, asymmetric, has an essentially identical API, and is faster, better designed, and has a bunch of new features. The symmetric token is the only feature present in symmetric that won't be part of asymmetric. Other than that, you can port your code performing a search and replace, replacing all the appearances of symmetric for asymmetric. Thank you for being a part of this project! Hope to see you around asymmetric!

Why Symmetric?

Raw developing speed and ease of use, that's why. symmetric is based on Flask! While Flask is a powerful tool to have, getting it to work from scratch can be a bit of a pain, especially if you have never used it before. The idea behind symmetric is to be able to take any module already written and transform it into a working API in a matter of minutes, instead of having to design the module ground-up to work with Flask (it can also be used to build an API from scratch really fast). With symmetric, you will also get some neat features, namely:

  • Auto logging.
  • Server-side error detection and exception handling.
  • Auto-generated /docs endpoint for your API with interactive documentation.
  • Native support for an authentication token on a per-endpoint basis.
  • Auto-generated OpenAPI Specification and Markdown documentation files for your API.

The complete documentation is available on the official website.

Installing

Install using pip!

pip install symmetric

Usage

Running the development server

To start the development server, just run:

symmetric run <module>

Where <module> is your module name (in the examples, we will be writing in a file named module.py, so the module name will be just module). A Flask instance will be spawned immediately and can be reached at http://127.0.0.1:5000 by default. We don't have any endpoints yet, so we'll add some later. Do not use this in production. The Flask server is meant for development only. Instead, you can use any WSGI server to run the API. For example, to run the API using gunicorn, you just need to run gunicorn module:symmetric and a production ready server will be spawned.

Defining the API endpoints

The module consists of a main object called symmetric, which includes an important element: the router decorator. Let's analyze it:

from symmetric import symmetric

@symmetric.router("/some-route", methods=["post"], response_code=200, auth_token=False)

The decorator recieves 4 arguments: the route argument (the endpoint of the API to which the decorated function will map), the methods argument (a list of the methods accepted to connect to that endpoint, defaults in only POST requests), the response_code argument (the response code of the endpoint if everything goes according to the plan. Defaults to 200) and the auth_token argument (a boolean stating if the endpoint requires authentication using a symmetric token. Defaults to False).

Now let's imagine that we have the following method:

def some_function():
    """Greets the world."""
    return "Hello World!"

To transform that method into an API endpoint, all you need to do is add one line:

@symmetric.router("/sample", methods=["get"])
def some_function():
    """Greets the world."""
    return "Hello World!"

Run symmetric run module and send a GET request to http://127.0.0.1:5000/sample. You should get a Hello World! in response! (To try it with a browser, make sure to run the above command and click this link).

But what about methods with arguments? Of course they can be API'd too! Let's now say that you have the following function:

def another_function(a, b=372):
    """
    Adds :a and :b and returns the result of
    that operation.
    """
    return a + b

To transform that method into an API endpoint, all you need to do, again, is add one line:

@symmetric.router("/add")
def another_function(a, b=372):
    """
    Adds :a and :b and returns the result of
    that operation.
    """
    return a + b

Querying API endpoints

To give parameters to a function, all we need to do is send a json body with the names of the parameters as keys. Let's see how! Run symmetric run module and send a POST request (the default HTTP method) to http://127.0.0.1:5000/add, now using the requests module.

import requests

payload = {
    "a": 48,
    "b": 21
}
response = requests.post("http://127.0.0.1:5000/add", json=payload)
print(response.json())

We got a 69 response! (48 + 21 = 69). Of course, you can return dictionaries from your methods and those will get returned as a json body in the response object automagically!

With this in mind, you can transform any existing project into a usable API very quickly!

ReDoc Documentation

By default, you can GET the /docs endpoint (using a browser) to access to interactive auto-generated documentation about your API. It will include request bodies for each endpoint, response codes, authentication required, default values, and much more!

Tip: Given that the ReDoc Documentation is based on the OpenAPI standard, using type annotations in your code will result in a more detailed interactive documentation. Instead of the parameters being allowed to be any type, they will be forced into the type declared in your code. Cool, right?

Developing

Clone the repository:

git clone https://github.com/daleal/symmetric.git

cd symmetric

Recreate environment:

./environment.sh

. .venv/bin/activate

Test install:

poetry install  # will also install the symmetric CLI

Run the tests:

python -m unittest

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].