The Web API toolkit. ๐Ÿ› 

Overview

API Star

๐Ÿ›  The Web API toolkit. ๐Ÿ› 

Build Status codecov Package version


Community: https://discuss.apistar.org ๐Ÿค” ๐Ÿ’ญ ๐Ÿค“ ๐Ÿ’ฌ ๐Ÿ˜Ž

Documentation: https://docs.apistar.com ๐Ÿ“˜

Requirements: Python 3.6+


API Star is a toolkit for working with OpenAPI or Swagger schemas. It allows you to:

  • Build API documentation, with a selection of available themes.
  • Validate API schema documents, and provide contextual errors.
  • Make API requests using the dynamic client library.

You can use it to build static documentation, integrate it within a Web framework, or use it as the client library for interacting with other APIs.

Quickstart

Install API Star:

$ pip3 install apistar

Let's take a look at some of the functionality the toolkit provides...

We'll start by creating an OpenAPI schema, schema.yaml:

openapi: 3.0.0
info:
  title: Widget API
  version: '1.0'
  description: An example API for widgets
servers:
  - url: https://www.example.org/
paths:
  /widgets:
    get:
      summary: List all the widgets.
      operationId: listWidgets
      parameters:
      - in: query
        name: search
        description: Filter widgets by this search term.
        schema:
          type: string

Let's also create a configuration file apistar.yml:

schema:
  path: schema.yaml
  format: openapi

We're now ready to start using the apistar command line tool.

We can validate our OpenAPI schema:

$ apistar validate
โœ“ Valid OpenAPI schema.

Or build developer documentation for our API:

$ apistar docs --serve
โœ“ Documentation available at "http://127.0.0.1:8000/" (Ctrl+C to quit)

We can also make API requests to the server referenced in the schema:

$ apistar request listWidgets search=cogwheel

Where did the server go?

With version 0.6 onwards the API Star project is being focused as a framework-agnostic suite of API tooling. The plan is to build out this functionality in a way that makes it appropriate for use either as a stand-alone tool, or together with a large range of frameworks.

The 0.5 branch remains available on GitHub, and can be installed from PyPI with pip install apistar==0.5.41. Any further development of the API Star server would likely need to be against a fork of that, under a new maintainer.

If you're looking for a high-performance Python-based async framework, then I would instead recommend Starlette.


API Star is BSD licensed code.
Designed & built in Brighton, England.

API Star

Comments
  • Towards 0.4

    Towards 0.4

    Lots of big changes here. I'll keep the synopsis to a minimum...

    • Rewrite type system. (Don't use type subclasses, just plain old python objects please.)
    • Rewrite components. (Much simpler. Components as plain objects allows per-component configuration, rather than everything in a big global settings dict.)
    • Add event hooks.
    • ASGI becomes the asyncio interface, since it's latest re-write now supports our requirements.
    • OpenAPI to become the default schema representation.
    • Drop coreapi and coreschema - Schema generation and client library is now part of this package.
    • Drop built-in support for ORMs, push towards third-party instead.

    Here's the README

    TODO:

    • [x] Format support, eg. 'datetime' validation.
    • [x] Enforce location=query|path|body
    • [x] Enforce path fields as required, and matching uritemplate.
    • [x] Remove uritemplate dependency.
    • [x] Support Type.
    • [x] Deal with non-unique names in Routing (asserts at document level)
    • [x] Include Type and annotation information on schema.
    • [x] Allow Type subclasses to be used in validations.
    • [x] ASyncIO Support, with ASGI
    • [x] Static Files support for ASGI
    • [x] Update uvicorn for ASGI Support - See https://github.com/encode/uvicorn/pull/63
    • [x] Resolve issue with dependency injection not persisting parameters between functions.
    • [x] Clean up TODOs in docs.

    Later:

    • [ ] Add url to Section.
    • [ ] Guard against uvicorn calling into old-style interface, and yell loudly.
    • [ ] Response schemas in OpenAPI.
    • [ ] Consider types/fields instead of types/validators.
    • [ ] Bool and null coercions for query string and form data.
    • [ ] Use ConfigurationError, not assert
    • [ ] Subclassing Type and handling allOf relationships in JSON schema.
    • [ ] Reintroduce API docs.
    • [ ] Reintroduce command routing.
    • [ ] Test coverage & fixups.
    • [ ] Third-party Flask, Django variants.
    • [ ] Check for configuration errors when instantiating router from Document.
    • [ ] Use url not base_url for decode option from HTTPTransport.
    • [ ] Support errors override on type system.
    • [ ] Client should validate path/query/body parameters are appropriate primitive types only.
    opened by tomchristie 31
  • CORS Support

    CORS Support

    Using any API from the browser obviously requires support for CORS. Django and Flask have several ways to integrate this, and I'd love to see that in this project. Not sure what the most effective way to enable this is.

    In a small API I built just recently, I've got it hardcoded, but it would be great to identify the headers, and turn it on.

    Component 
    opened by kinabalu 29
  • allow changing folder in which app.py resides

    allow changing folder in which app.py resides

    This PR allows changing the folder in which app.py resides by setting APISTAR_FOLDER environment variable. If you wanted to allow changing the filename of app.py as well, you could supply the full path to the file and rename the environment variable to APISTAR_APP, more akin to flask.

    fixes #258

    opened by AlJohri 17
  • Issue with reloader for `apistar run` on Windows.

    Issue with reloader for `apistar run` on Windows.

    After the discussion on discourse, and #196 , #207 I think we can say there is an issue with windows.

    From the discussion on discourse it looks like the issue is with the app = get_current_app() line, where the app isn't being properly obtained. This is based on the comment that when pasting the app into run.py it worked

    get_current_app() is defined in cli.py and I bet the issue is with the path resolution on windows. I don't have a windows system to test it out though, but all one would need to do is put a import pdb; pdb.set_trace() statement at the start of that function and step through to see where the path is resolving too.

    Bug 
    opened by audiolion 15
  • SQL Alchemy Backend

    SQL Alchemy Backend

    Example usage: https://gist.github.com/maximilianhurl/cb5507354fc8be812c1e3a578627001f

    • [x] Move SQL Alchemy initialisation into component
    • [x] Add command to create tables
    • Add db tests;
      • [x] SQLite
      • [x] PostgreSQL
    • [x] Pull config from settings
    • [x] Add documentation to readme

    Future:

    • [ ] Add support or documentation for migrations
    • [ ] Use environment settings for db config
    • [ ] Add preloaded component (once available)
    opened by maximilianhurl 14
  • Exception handling

    Exception handling

    Closes #437. Closes #443. Closes #449. Closes #423. Closes #219.

    • on_response now runs for both regular reponses and handled exceptions.
    • on_error now only runs for unhandled exceptions (ie. 500 reponses).
    • Return 500 responses on error.
    • Test client raises exceptions instead of returning 500 responses.
    • Add debug flag to app.serve(), to switch between debugger vs. plain responses.
    opened by tomchristie 13
  • apistar project still active?

    apistar project still active?

    howdy,

    first of all, thanks for that great project; very intuitive and ambitiously work. currently i'm in the research phase for a python api framework for a bigger project. apistar would be my favourite.

    having that said, my impression is that this project kind of stalled. a couple of open, unanswered pull requests and issues. anybody here, who has insights about the motivation and development? are there others than @tomchristie who are maintainers?

    i would be not only interested to use this framework, but also to contribute to the missing response types part. this of course would be another discussion, in case of active maintainers existent.

    best, andi

    opened by pansen 13
  • Version 0.2 - asyncio support.

    Version 0.2 - asyncio support.

    Pretty serious re-working in progress here. For an overview you'll want to review the source code of the branch itself rather than attempting to review the diff.

    Take a look in particular at interfaces.py and app.py. You'll see that the dependency injection has been completely reworked, and that overriding components on applications looks far neater.

    The end result of this work is going to be the ability for API Star to support multiple types of application. asyncio is the obvious first target here, but I'd also like us to have Flask and Django variants. Having the ability to use their ORMs as we currently have is okay, but users still miss out on a vast amount of existing ecosystem.

    Update: This branch now introduces asyncio support.

    More work on this to come, but looking rather nice so far.

    • [x] MultiDict for headers and queryparams.
    • [x] Schema -> Components.
    • [x] Finesse interface.py/types.py.
    • [x] Finesse view names.
    • [x] CLI support.
    • [x] Component pre-loading.
    • [x] Support defaults on params.
    • [x] Include support.
    • [x] Use Routes in preference to Router in components.
    • [x] Reintroduce remaining commands, and apistar main cli.
    • [x] Clean up response generation.
    • [x] Coverage -> 100%
    • [x] Simplify type->schema mapping.
    • [x] Compile changelist.
    • [x] Update docs.
    • [x] Add asyncio docs.
    • [x] Add Command docs.
    • [x] Improve formatting of argparse commands.
    • [x] Test API docs against 0.2
    • [x] Finish remaining asyncio coverage.
    • [x] Add run command for asyncio.
    • [x] Case-insensitivity on headers.
    • [x] Review typing.newtype() vs typing.integer(...) (Sticking with newtype for now)
    • [x] Reintroduce ORM components.
    • [x] Review statics/sendfile. Consider static docs generation.
    • [x] pip install apistar[asyncio], and update apistar new --layout to apistar new --framework
    • [x] Reintroduce test command, at least for now.
    • [x] Inline typesystem declarations.
    • [x] Review settings.
    • [ ] Finesse exception handling. 500 vs raise.
    • [ ] CORS handling in finalize_response.
    • [ ] Add backend testing docs for DB setup/teardown.
    • [ ] Support additional arguments in command line (eg. makemigrations)

    Later:

    • Remove coreschema, move form rendering into API Star. Add render_form, render_link.
    • ~~Asyncio support.~~
    • Flask support.
    • Django support.
    • ~~Reintroduce ORM components.~~
    • Schema as a well-defined interface.
    • Consider moving away from global settings.
    • Make standalone usage of app.injector easier, eg. static_files = app.injector.run(StaticFiles), update corresponding test cases.
    • Better messages on injector configuration errors. (Use function and parameter name, not Parameter)
    • Coerce primitive types to typesystem types for the purposes of stricter behavior (eg. inf) and validation error messages.
    • Check for repeated list/dict in annotations, or list/dict on GET requests.
    • Support explicit location overrides on parameters.
    • Support form renderering list/dict type schemas fully, and schema output.
    • Support type aliases as parameter annotations. typing.List, typing.NewType etc...
    • Support defaults in params for HTTP.
    • Error details on 404. Consider removing "messages" and always error by key.
    • Finesse argparse support (use help/description generation for schemas too. support list/dict/enum)
    • Support async context managers.
    • Finesse Injector interface for sync/async, and raise error in sync case if coroutines are included.
    • Add logging to components throughout.

    Changelist: See README.

    Closes #29

    opened by tomchristie 13
  • Migrations support

    Migrations support

    Alembic seems to be the go-to choice for SQLAlchemy, but I don't have any experience personally of eg. what the alternatives are, or how this stacks up against Django's migrations framework.

    http://alembic.zzzcomputing.com/

    Enhancement 
    opened by tomchristie 13
  • Schema validation & annotation

    Schema validation & annotation

    We have some of this in place at the moment, but we still need:

    • [x] Object
    • [x] Array
    • [x] Enum
    • [x] Documentation
    • [x] Defaults on schema types.
    • [x] Nullable

    Plus a whole bunch of finessing around things like:

    • Keyword defaults on handler functions.
    • Support List in handler input types.
    • Coerce primitive types to schema types? (eg. bool then handles "True"/"False" string literals, str then trims whitespace by default.)
    • Returning aggregated validation errors for multiple parameters.
    • Which typing annotations we support in views.
    • Native formats such as datetime that have a string serialization.
    • If we want to constrain the typing system against GraphQL, eg. no general "Map" type.
    Baseline feature 
    opened by tomchristie 13
  • Introduce black to format source code

    Introduce black to format source code

    In this PR as @tomchristie requested to introduce black first as a source code formatting tool at https://github.com/encode/apistar/pull/442. Next PR will be with auto-formatted APIStar source and contributor docs explaining how enable automatic code formatting if needed.

    Thanks.

    opened by sultaniman 12
  • Can you publish a wheel?

    Can you publish a wheel?

    If one is in an environment where sdist is prohibited and only wheels are allowed (as a security mitigation), it would be handy for a wheel to have been published.

    If you add bdist_wheel here: https://github.com/encode/apistar/blob/8015bc1b3c9f43bcf9baa8407330338224232689/scripts/publish#L18

    making python setup.py sdist bdist_wheel then it will build a wheel and you can upload it to pypi

    Thanks!

    opened by matthewdeanmartin 0
  • Doing async requests

    Doing async requests

    Just found out to my surprise that the apistar client does not support async requests. As this project seems rather dead, maybe someone knows a similar one that implement async? did some overriding to achieve it in a hacky way: https://gist.github.com/kelvan/49e3efb99c329b4c2476d49458b19c19

    opened by kelvan 3
  • [Issue-657] Appending path to server url

    [Issue-657] Appending path to server url

    Fix for the problem stated in issue #657

    According OpenApi standard: "A relative path to an individual endpoint. The field name MUST begin with a forward slash (/). The path is appended (no relative URL resolution) to the expanded URL from the Server Object's url field in order to construct the full URL."

    *Added tests to test_openapi

    opened by QFer 0
  • Consistently name schema YAML file as schema.yml

    Consistently name schema YAML file as schema.yml

    As per the following issues, the documentation mixes between yaml and yml file extensions for the apistar and schema YAML files when the apistar file explicitly needs to have the yml extension. This PR amends the documentation for references to the schema YAML file to have the yml extension.

    #630 #670 #651

    opened by omussell 0
  • Unable to run .exe file

    Unable to run .exe file

    Please help someone to get this resolve. I am facing this issue while converting .py file to exe. File conversion is successful but while running .exe file its not executing. I searched for answer but no solution related to this error.

    Error :- SyntaxError: Non-UTF-8 code starting with '\x90' in file Daily_PM_Guj.exe on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

    opened by github-pawan 0
Owner
Encode
Collaboratively funded software development.
Encode
Browsable web APIs for Flask.

Flask API Browsable web APIs for Flask. Status: This project is in maintenance mode. The original author (Tom Christie) has shifted his focus to API S

Flask API 1.3k Dec 27, 2022
Async Python 3.6+ web server/framework | Build fast. Run fast.

Sanic | Build fast. Run fast. Build Docs Package Support Stats Sanic is a Python 3.6+ web server and web framework that's written to go fast. It allow

Sanic Community Organization 16.7k Dec 28, 2022
Web APIs for Django. ๐ŸŽธ

Django REST framework Awesome web-browsable Web APIs. Full documentation for the project is available at https://www.django-rest-framework.org/. Fundi

Encode 24.7k Jan 4, 2023
A JSON Web Token authentication plugin for the Django REST Framework.

Simple JWT Abstract Simple JWT is a JSON Web Token authentication plugin for the Django REST Framework. For full documentation, visit django-rest-fram

Jazzband 3.3k Jan 4, 2023
Django Ninja is a web framework for building APIs with Django and Python 3.6+ type hints.

?? Fast, Async-ready, Openapi, type hints based framework for building APIs

Vitaliy Kucheryaviy 3.8k Jan 4, 2023
Document Web APIs made with Django Rest Framework

DRF Docs Document Web APIs made with Django Rest Framework. View Demo Contributors Wanted: Do you like this project? Using it? Let's make it better! S

Manos Konstantinidis 626 Nov 20, 2022
a web-remote minecraft server wrapper with some unique features

Canceled here, continued as Semoxy MCWeb - a Minecraft Server Web Interface MCWeb is a web-remote Minecraft Server Wrapper for controlling your Minecr

Anton Vogelsang 1 Jul 12, 2021
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.6k Jan 4, 2023
Automatically generate a RESTful API service for your legacy database. No code required!

sandman2 sandman2 documentation [ ~ Dependencies scanned by PyUp.io ~ ] sandman2 automagically generates a RESTful API service from your existing data

Jeff Knupp 1.9k Jan 7, 2023
Restful API framework wrapped around MongoEngine

Flask-MongoRest A Restful API framework wrapped around MongoEngine. Setup from flask import Flask from flask_mongoengine import MongoEngine from flask

Close 525 Jan 1, 2023
Kong API Manager with Prometheus And Splunk

API Manager Stack Run Kong Server + Konga + Prometheus + Grafana + API & DDBB + Splunk Clone the proyect and run docker-compose up

Santiago Fernandez 82 Nov 26, 2022
Django REST API with React BoilerPlate

This is a setup of Authentication and Registration Integrated with React.js inside the Django Templates for web apps

Faisal Nazik 91 Dec 30, 2022
Estudo e desenvolvimento de uma API REST

Estudo e desenvolvimento de uma API REST ??โ€?? Tecnologias Esse projeto utilizarรก as seguintes tecnologias: Git Python Flask DBeaver Vscode SQLite ??

Deusimar 7 May 30, 2022
Example Starlette REST API application

The idea of this project is to show how Starlette, Marshmallow, and SQLAlchemy can be combined to create a RESTful HTTP API application that is modular, lightweight, and capable of dealing with many simultaneous requests.

Robert Wikman 0 Jan 7, 2022
RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

Microsoft 1.8k Jan 4, 2023
JSON:API support for Django REST framework

JSON:API and Django REST framework Overview JSON:API support for Django REST framework Documentation: https://django-rest-framework-json-api.readthedo

null 1k Dec 27, 2022
Django-rest-auth provides a set of REST API endpoints for Authentication and Registration

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)

Tivix 2.4k Dec 29, 2022
One package to access multiple different data sources through their respective API platforms.

BESTLab Platform One package to access multiple different data sources through their respective API platforms. Usage HOBO Platform See hobo_example.py

Wei 1 Nov 16, 2021