Nautica API
- 9 Devlogs
- 25 Total hours
Nautica is the backend platform that manages the runtime, lifecycle, routing and 3rd party plugins automatically.
Nautica is the backend platform that manages the runtime, lifecycle, routing and 3rd party plugins automatically.
A video demonstration:
nested(...) to {...}
help
Reply.IsList() into .asList()
Requirements in napi
These are mostly QoL changes, I made formatting of certain things so it’d be easier to read, use, or to make sense linguistically. I also made it a little bit more secure by giving other developers an option to hide their request schemas in error messages. I’ve also included the new benchmark numbers in the README.
OpenAPI Docs generator mostly works now, but it doesn’t expose the docs to /nautica:docs yet, I’m also considering making the endpoint the developer’s concern, and not the framework’s. Surprisingly it wasn’t as hard as i expected it to be, but some weird edge cases were definitely annoying to deal with.
Anyways, alongside the updates to the framework itself, I’ve also now documented the new changes made since version 3.0.2, so they’re now up to date with the latest release (that being 3.2.2). I know it took a while but i was more focused on releasing fixes and updates first.
I’ve started work on OpenAPI Docs generator, I’d imagine it’ll take me a while to complete. Anyways I’ve released v3.2, see below for new changes
onSetup hook for servicesRequire.ListOf validatorMore on these changes here: post 1, post 2
And new, undocumented changes include:
7. Moving typeToString into models, from http api (didn’t really make sense to have it there)
8. Added static methods into Reply for starlette responses, these include:
Reply.plainText,Reply.html,Reply.stream,Reply.file,Reply.redirect.
v3.2.0’s dependency resolver incorrectly handles the :after parameter, a fix is already available in the branch for version 3.2.1
I’ve added a few QoL features, those being:
Before, you could only verify whats coming IN, but not whats coming OUT of the server. Now, you can do that easily:
from napi.http import HTTP, Reply, Require, ReplyModel, Error
@HTTP.GET()
@HTTP.Responses(
ReplyModel(200, str),
ReplyModel(400, Error),
strict= True
)
@HTTP.Require()
async def hello(ctx):
if ctx.body.get("hello"): raise Error(400, "No hello")
return "Hello World!"
In this case, the request will go through without an issue, but if, for example, you returned anything other than a string:
return 0
The request will fail automatically. This will also be useful for when I add OpenAPI generation, as the generator will have access to the responses.
This behavior can be disabled, by setting strict to False.
@HTTP.Require(body = {"hello": {"world": str}) <- This code used to be invalid before.
I since added support for nested objects (no depth limit).
Plugins used to register their own keys in the config, and then setup isEnabled method that would determine if the service should be started or not.
To reduce the headache and boilerplate of this approach, Nautica now automatically creates a key with your service’s name under services in config.n3. If you want your own logic in isEnabled, you can do so by overwriting the method. By doing so you’ll disable the automatic registration and the framework gives you the freedom to do it your way. If you want custom logic AND automatic registration, it can simply be combined by using super().isEnabled().
I’d say this is a highly useful addition. It does exactly what it sounds like: It checks if all the items in a list match a certain schema.
Require.ListOf(str)
List of just strings
Require.ListOf({"hello": str})
List of dictionaries
Requrie.ListOf(Require.AnyTypeOf(str, int))
List of strings and integers
I’ve been optimizing the framework today, here’s what changed:
I managed to go from 2279 requests/sec to 3929, which is 72% increase. After running new benchmarks, I’ve also surpassed FastAPI by ~24% (recorded 3154 requests/sec). I did this by minimizing the amount of logging that is done per request (can be configured). Because my log manager is fairly heavy, this helped a lot.
The dependency resolver I had for services was okay, but it lacked 2 important features: Optional dependencies and explicit order.
Service.Export(MyPlugin, depends_on=["HTTPRouter"])
Which is fine for simple plugins, but you start doing more complex work, you’ll hit the limits fast.
? at the end makes the dependency optional:after tells the dependency to start AFTER your plugin, not before. Essentially adds your plugin as the target’s dependency.
Before, onStart handled both starting database and HTTP servers, bots. Because of this, I’ve decided to split the setup logic and startup logic into 2: onSetup and onStart
I also removed some legacy aliases for methods.
Spent almost 5 hours on a navbar, finally figured it out though.
The open/close logic on hovering was a nightmare to do. In the end i settled for IDs and an event listener for mouseover. It’s probably one of the worse solutions, but I’m not gonna touch it since it works finally.
I also changed the background to something that fits better.
I’ve started work on a web for the framework.
For now I only managed to set up the project and make the hero on the landing page, for which I took inspiration from payloadcms and rig.ai
The landing page itself was hard to make, since I had to figure out how to structure the grid, and even now it’s not up to my standards.
Nautica Package Registry is Live!
napi install mongodb now downloads the package into project plugins and installs any PyPI dependencies automatically.
2 Packages are up already:
The registry itself runs on Nautica, with both packages installed
https://github.com/xellu/nautica-package-manager
https://napm.xellu.xyz/
Hello y’all. I’m making a framework for backend development, called Nautica. I’m also bundling a package manager, similar to npm/PyPI, to allow people to share their plugins.
I’ve started working on this project before Stardance, but this sounds like a good opportunity to get feedback on it.
Today’s update notes (v3.1.3):
For anyone interested in the specifics, the HTTP part of the API is built on top Starlette. Unlike FastAPI, I made my own request validation system that gives you more freedom, though it may perform worse under load.
From the benchmarks I’ve ran, my framework seems to be just a little faster than FastAPI (which is also based on Starlette):
I’m still working on the package manager, but I’ll post a showcase of that soon. For now, here’s a showcase of how Nautica itself works: