Code Monkey home page Code Monkey logo

fasthx's Introduction

Hi,

Iโ€™m Peter Volf, SW engineer for many years now with a master's degree in computer science, located in Hungary.

My main professional interest has been Python ever since I first started using it around ~2008. I really enjoy working with React and TypeScript, and doing full-stack application development as well. I'm also interested in Linux and the open-source world in general. At university, I specialized in network/graph analysis and machine learning -- it was a long time ago, it would be great to have the time to pick these up again.

I work mostly on greenfield web projects. When my time allows -- unfortunately not nearly as often as I'd like these days -- I like to do some open-source work.

Some of my more interesting hobby projects are:

  • localclustering is a local graph clustering algorithm with a graphscraper backend (JOSS publication, analysis).
  • motorhead is an async almost-ODM for MongoDB with vanilla Pydantic v2.
  • fasthx is an HTMX utility for FastAPI.
  • graphscraper is an SQL graph database with an in-memory cache and a built-in, on-demand web scraper.
  • mastodon-social-graph is a graphscraper implementation that loads the social graph of a Mastodon instance.
  • uspto-patent-citation-graph is a graphscraper implementation that loads the citation graph from USPTO's API.
  • markyp is an XML templating engine and parser tool.
  • markyp-html is an HTML implementation based on markyp that lets you write static webpages 100% in Python (i.e., without Jinja-like templating).
  • markyp-bootstrap4 is a full Bootstrap4 implementation based on markyp-html.

My recent professional projects:

  • Currently I work on AI-assisted digital healthcare services AIP Clinic and AIP Derm, on the LNGx platform, and on various internal business tools.
  • Horizon Planner, an enterprise resource planning and project management application (tech lead/principal engineer, 2019-2023).

I also tutor engineers, from juniors to seniors, primarily focusing on Python and system architecture/design.

I'm available for consulting and contract work, you can find me on:

fasthx's People

Contributors

hasansezertasan avatar volfpeter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fasthx's Issues

Add more examples

README.md is quite good but I think there must be a folder called "examples" for fully-fledged examples with templates folder and Jinja2 templates.

Template per Response Code

Hey,

would it be possible to define a template per response code? This would make it easier, to render a different template, e.g. in case of validation errors of API input or other situations (e.g. item not found ...).

I understand that it would likely also be possible to have that logic within the template (if the response object is made available), but it might be need lees boilerplate code to be able to see that directly in the Python code.

Henning

Unable to access Response in the Route

Problem statement: Unable to access Response in the route (e.g. setting cookies) as it's being handled by fasthx.

Currently using a workaround - hx-target to a hidden div for the returned JWT tokens, and use JS to detect the response code and redirect the browser.

Would be nice if we could access Response from within the route.

Pass endpoint dependencies to Jinja context

We can not access endpoint dependencies from Jinja templates as of now. What if we change this block:

fasthx/fasthx/main.py

Lines 141 to 142 in 2003d8c

def render(result: Any, *, context: dict[str, Any], request: Request) -> HTMLResponse:
return self.templates.TemplateResponse(name=template_name, request=request, context=result)

as this:

        def render(result: Any, *, context: dict[str, Any], request: Request) -> HTMLResponse:
            result.update({"depends": context})
            return self.templates.TemplateResponse(name=template_name, request=request, context=result)

Maybe another name for the key, private instead of depends?

Returning HX-* headers with response

Hi,

As HTMX relies on returning HX-* Header for certain functionality like triggers, I was wondering how to send these with fasthx?

I tried like this, but that seems to get filtered for HTMX responses:

response.headers["HX-Trigger"] = "newPortfolio"

# Add new
@router.post("/", response_model=PortfolioCreate)
@jinja.hx("portfolios/portfolio.jinja2")
async def create(response: Response, portfolio: PortfolioCreate, db: Session = Depends(database.get_db)):
    response.headers["HX-Trigger"] = "newPortfolio"
 ...
    return record

The json response is correct though:

< HTTP/1.1 200 OK
< date: Tue, 26 Mar 2024 11:26:16 GMT
< server: uvicorn
< content-length: 38
< content-type: application/json
< hx-trigger: newPortfolio
< 
* Connection #0 to host localhost left intact
{"name":"Portfolio3","description":""}

Ollie.

Allow non-dict return values by default for Jinja template rendering

Currently the route must return a dict (which is a bit hidden by the Any type).

The decorator should at least handle these cases by converting them to a dict (Jinja rendering context): dict, pydantic.BaseModel (both v1 and v2), objects with __dict__ or __slots__. Maybe Iterables should also be accepted, the Jinja context in that case could be {"items": [r for r in result]}.

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.