Skip to main content

A light weight Python async framework with batteries included.

Project description

A light weight Python async framework with batteries included

Build Documentation Status image image image image

import dyne

api = dyne.API()

@api.route("/create", methods=["POST"])
@api.authenticate(basic_auth, role="user")
@api.input(BookCreateSchema, location="form")
@api.output(BookSchema)
@api.expect(
    {
        401: "Invalid credentials",
    }
)
async def create(req, resp, *, data):
    """Create book"""

    image = data.pop("image")
    await image.save(image.filename)  # File already validated for extension and size.

    book = Book(**data, cover=image.filename)
    session.add(book)
    session.commit()

    resp.obj = book

if __name__ == "__main__":
  api.run()

Powered by Starlette. View documentation.

This gets you a ASGI app, with a production static files server pre-installed, jinja2 templating (without additional imports), and a production webserver based on uvloop, serving up requests with gzip compression automatically.

More Examples

See the documentation's feature tour for more details on features available in dyne.

Installing dyne

Install the stable release:

pip install dyne

The Basic Idea

The primary concept here is to bring the niceties that are brought forth from both Flask and Falcon and unify them into a single framework, along with some new ideas I have. I also wanted to take some of the API primitives that are instilled in the Requests library and put them into a web framework. So, you'll find a lot of parallels here with Requests.

  • Setting resp.content sends back bytes.
  • Setting resp.text sends back unicode, while setting resp.html sends back HTML.
  • Setting resp.media sends back JSON/YAML (.text/.html/.content override this).
  • Setting resp.obj deserializes SQLAlchemy object(s) using Pydantic or Marshmallow schemas
  • Case-insensitive req.headers dict (from Requests directly).
  • resp.status_code, req.method, req.url, and other familiar friends.

Ideas

  • Flask-style route expression, with new capabilities -- all while using Python 3.6+'s new f-string syntax.
  • I love Falcon's "every request and response is passed into to each view and mutated" methodology, especially response.media, and have used it here. In addition to supporting JSON, I have decided to support YAML as well, as Kubernetes is slowly taking over the world, and it uses YAML for all the things. Content-negotiation and all that.
  • A built in testing client that uses the actual Requests you know and love.
  • The ability to mount other WSGI apps easily.
  • Automatic gzipped-responses.
  • In addition to Falcon's on_get, on_post, etc methods, dyne features an on_request method, which gets called on every type of request, much like Requests.
  • A production static file server is built-in.
  • Uvicorn built-in as a production web server. I would have chosen Gunicorn, but it doesn't run on Windows. Plus, Uvicorn serves well to protect against slowloris attacks, making nginx unnecessary in production.
  • GraphQL support, via Graphene. The goal here is to have any GraphQL query exposable at any route, magically.
  • Provide an official way to run webpack.

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

dyne-1.0.7.tar.gz (8.9 MB view details)

Uploaded Source

Built Distribution

dyne-1.0.7-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file dyne-1.0.7.tar.gz.

File metadata

  • Download URL: dyne-1.0.7.tar.gz
  • Upload date:
  • Size: 8.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for dyne-1.0.7.tar.gz
Algorithm Hash digest
SHA256 6060385b4ddb56db44b32c61e82acb973bcfb1f9e10d216acb0b126989c13a77
MD5 2143a0e6fc58901dbb93ff36107f6a15
BLAKE2b-256 040796d7edbbc4bd70ca7ccf3bdeb812e2faa648924de317ad3057806b3d23ec

See more details on using hashes here.

File details

Details for the file dyne-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: dyne-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 38.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for dyne-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 cb83978ffab34ce2b16c43271c21d7a515bff748a2b16be285dffcd7fcaad380
MD5 bb22b1a37d6e91fcb8b3342ea545bf7b
BLAKE2b-256 3e8c1de7081f8a99311cb1972d18fa0af82ffc2266ef45445451df02f41c2b37

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