This project has been archived by its maintainers, and is no longer receiving any updates.
Rustoken
Rustoken is a Python library written in Rust that can create and decode JWT tokens.
This is the first version of the library and it currently supports only the HS256 algorithm.
How to install:
pip install rustoken
make sure if its installed:
$ rstoken version
help command:
$ rstoken --help
How to make SECRET-KEY in Rustoken:
from rustoken import secret_key
secret_key = secret_key() # save it to .env file
print(secret_key)
How to make SECRET-KEY on CLI:
$ rstoken secret
Noraml Usage:
from rustoken import RustToken
jwt = RustToken("MY-SECRET-KEY") # better to use .env file
access = jwt.create_token(new_user.id, 24 * 60 * 60) # 1 day
refresh = jwt.create_token(new_user.id, 24 * 60 * 60 * 7) # 7 day exp
Usage In Fast-Api:
from rustoken import RustToken
from fastapi import FastAPI, Depends
from sqlalchemy.orm import Session
from . import models, schemas, database
app = FastAPI()
models.Base.metadata.create_all(bind=database.engine)
def get_db():
db = database.SessionLocal()
try:
yield db
finally:
db.close()
@app.post("/make-user/", response_model=schemas.UserResponse)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
new_user = models.User(username=user.username, email=user.email)
db.add(new_user)
db.commit()
db.refresh(new_user)
#<------------------------------------------------------->
jwt = RustToken("MY-SECRET-KEY") # better to use .env file
access = jwt.create_token(new_user.id, 24 * 60 * 60) # 1 day
refresh = jwt.create_token(new_user.id, 24 * 60 * 60 * 7) # 7 day exp
return {"refresh_token": refresh, "access_token": access}
NOTE: The expiration time is in seconds
How to decode Tokens:
from rustoken import RustToken
jwt = RustToken("MY-SECRET-KEY") # better to use .env file
token = "eyJ0eXAiOiJKV1QiLCJhbGciO..."
try:
jwt.decode(token)
except ValueError:
# if token is expired it return a ValueError
...
Metadata
Release files for rustoken 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rustoken-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.34+ x86-64 | Details for rustoken-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl |
Release files / rustoken-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | rustoken-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 830.4 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
96ff03695a467c11523f3181a4fd929a62ae38bfabae91cb4b87ef578415f6cd
|
|
BLAKE2b-256 checksum How to use checksums |
c9b5bec99b842a4c7cc5e020a4e20b1c3a0147b9c703f8b659bf0882ae35a291
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for rustoken 0.1.5
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.