Skip to main content

spic

Status Code Coverage Ruff Hatch project PyPI - Version PyPI - Python Version Wheel Snyk


spic

Table of Contents

Intro

spic is an ASGI based api router with minimal dependencies and strong typing.

Rationale

  • popular libraries have dependencies which are moving commercial
  • no popular libraries for core python dataclass structures

Features

familiar methods

# ./main.py

from spic.app import Slip

app = Slip(title="my-api", version="0.1")

@app.get("/health")
async def status_handler():
    return {"status": "healthy ✨"}

app.collapse() # collapse routes

# hypercorn main:app --reload

dependency injection

# ./main.py

from spic.params import Header, Query

...

@app.get("/merged")
async def merged_params(x_usr_token: Header[str], query: Query[str]):
    return {
        "X-Usr-Token": x_usr_token,
        "query", query
    }


app.collapse()

dataclass support

# ./main.py
from dataclasses import dataclass
from spic.params import Header, Query

...

@dataclass
class QueryArgs:
    query: Query[str]
    x_usr_token: Header[str]

@app.get("/class_base")
async def model_params(model: QueryArgs):
    return {
        "X-Usr-Token": model.x_usr_token,
        "query", model.query
    }

generic dataclass serialization (pyserde)

# ./models.py
from serde import serde
from dataclasses import dataclass

@serde
@dataclass
class QueryArgs:
    query: Query[str]
    x_usr_token: Header[str]

# OR

# ./models.py
from spic.utils import schema

@schema
class QueryArgs:
    query: Query[str]
    x_usr_token: Header[str]

...
# ./main.py
...
@app.get("/serializable")
async def get_model(model: QueryArgs):
    return model # json

beartype validation

# ./client.py
from httpx import get
...

get(
    "http://localhost:8000/class_base?query=query-str-value" # missing header
).json()
# powered by beartype

# >> {
# >>  "errors": [
# >>    {
# >>      "key": "X_Usr_Token",
# >>      "expected": "string",
# >>      "given": "None",
# >>      "sources": ["header"]
# >>    }
# >>  ]
# >> }

performance

We currently test 3 primary use cases:

  • request param args -> function kwargs (no metaclass & valid)
    • 1.953ms overhead deserialization + reserialization (1000 ops)
  • request param args -> metaclass kwargs (dataclass)
    • 2.718ms overhead deserialization + reserialization (1000 ops)
  • invalid request param -> metaclass kwargs (raises errors & generates exception subclass)
    • 2.865ms overhead deserialization + reserialization (1000 ops)

Installation

pip install spic[core]

License

spic is distributed under the terms of the MIT license.

Metadata

Release files for spic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spic 0.1.0
File Size Uploaded Provenance Actions
spic-0.1.0.tar.gz 30.2 kB Without provenance Details for spic-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spic 0.1.0
File Interpreter ABI Platform Actions
spic-0.1.0-py3-none-any.whl Python 3 none any Details for spic-0.1.0-py3-none-any.whl

Total release size: 55.0 kB

Release files / spic-0.1.0.tar.gz

Download URL spic-0.1.0.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ea5b343d5fdfe0e43fa2f95f3369cb59c9b9d1f409da036af5a6b937cff7a520
BLAKE2b-256 checksum
How to use checksums
053b91cf493d3eda57bb240711f60ef9356a7fbb38fa923926e74a8e82afcb7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.0

Release files / spic-0.1.0-py3-none-any.whl

Download URL spic-0.1.0-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c10cf9f341ca618cac417eca38d39349bcfedc38e3c072de9c364d340ccff3a
BLAKE2b-256 checksum
How to use checksums
c1c556c690a6851db607edc5897d5acd7be395a48b98bd87e1c039fcdc77c026
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.0

Security for spic 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page