{"id":19409680,"url":"https://github.com/seznam/nats-jwt-py","last_synced_at":"2025-08-02T04:04:46.118Z","repository":{"id":234229460,"uuid":"785600484","full_name":"seznam/nats-jwt-py","owner":"seznam","description":"Python library for creating JWTs for NATS ecosystem using nkeys","archived":false,"fork":false,"pushed_at":"2025-02-04T13:07:19.000Z","size":132,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-07-01T01:43:36.171Z","etag":null,"topics":["jwt","nats","nkeys","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seznam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-04-12T08:10:18.000Z","updated_at":"2025-03-01T04:47:54.000Z","dependencies_parsed_at":"2024-04-18T15:25:08.436Z","dependency_job_id":"9f6e2878-8c3f-4564-ada2-ad97b71db575","html_url":"https://github.com/seznam/nats-jwt-py","commit_stats":null,"previous_names":["seznam/nats-jwt-py"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/seznam/nats-jwt-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seznam%2Fnats-jwt-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seznam%2Fnats-jwt-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seznam%2Fnats-jwt-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seznam%2Fnats-jwt-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seznam","download_url":"https://codeload.github.com/seznam/nats-jwt-py/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seznam%2Fnats-jwt-py/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268333976,"owners_count":24233782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jwt","nats","nkeys","python","python3"],"created_at":"2024-11-10T12:12:47.220Z","updated_at":"2025-08-02T04:04:46.078Z","avatar_url":"https://github.com/seznam.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NATS jwt lib for python\n\nPython's library for generating JWT tokens for NATS server.\n\n## ⚠️ Warning ⚠️\n\u003e This library is not well-tested and is in the development stage.\n\u003e \n\u003e The Author(s) is not a developer of the NATS, so may not understand zen of the NATS.\n\n## Notes\n\n| Scope           | level | description                                                                                                                              |\n|-----------------|:-----:|------------------------------------------------------------------------------------------------------------------------------------------|\n| `Code`          |  ℹ️   | This library was inspired and based on [official NATS's go library](https://github.com/nats-io/jwt).                                     |\n| `Code`          |  ℹ️   | Author tried to save structure of code that `GoLang` version has, but it is not one-to-one due to languages specs.                       |\n| `Code`          |  ℹ️   | In this library there is [snippets.py](nats_jwt/v2/snippets.py) that is targeting to make creation of accounts and users easier.         |\n| `Tests`         |  ⚠️   | Tests not covering all code.                                                                                                             |\n| `Documentation` |  ℹ️   | NATS has powerful [documentation for JWT](https://docs.nats.io/running-a-nats-service/nats_admin/security/jwt). Recommended for reading. |\n\n## Code Example\n\n_Code examples are using `snippets.py` which is not part of the go library._\n\n### Create Operator from seed\n```python\nfrom nats_jwt.v2.snippets import Operator\nfrom nats_jwt.v2.account_claims import Export\nfrom nats_jwt.nkeys_ext import nkeys2\nimport nkeys\n\n# create raw seed - 32 'random' bytes\nraw_seed: bytes = nkeys2.create_seed()\n\n# create a new seed for operator. This seed now would look in base64 like:\n# SO...\nop_seed: bytes = nkeys2.encode_seed(nkeys.PREFIX_BYTE_OPERATOR, raw_seed)\n\n# Tip: Also operator, account and user seeds can be created via prepared functions\n# Note 1: those functions are returning nkeys.KeyPair objects (ed25519 generated keys)\n# Note 2: You can extract seed from KeyPair object by calling seed() method\n#\n# nkeys2.create_operator_pair()\n# nkeys2.create_account_pair()\n# nkeys2.create_user_pair()\n\n# now we can create an abstraction above this seed for operator operations\nop = Operator(seed=op_seed)\n\n# `create_account` will create new seed, KeyPair, AccountClaims with issuer set to operator's public key\n# also, `Account` snippet object has signer key pair as object attribute (`_skp`) and when jwt generation\n# is done jwt automatically is signed by this key pair (and `iat` is also set to current time).\nac = op.create_account(\"my_account\")\n\nac.claims.name = \"rewrite_name\"\nac.claims.nats.exports.append(Export(\"my_export\", \"MY.CUSTOM.SUBJECT.\u003e\"))\n\n# JWT for any snippet is generated by calling `jwt` property-method\njwt: str = ac.jwt\n\n# now we can verify this jwt by calling `verify` operator method\nif op.verify(jwt):\n    print(\"account JWT is valid\")\nelse:\n    # should not happen :D\n    print(\"account JWT is invalid\")\n\nus = ac.create_user(\"my_user\")\nif ac.verify(us.jwt):\n    print(\"user JWT is valid\")\nelse:\n    # should not happen :D\n    print(\"user JWT is invalid\")\n```\n\n## LICENSE\nThis library is licensed under the same LICENSE as the [NATS's go library](https://github.com/nats-io/jwt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseznam%2Fnats-jwt-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseznam%2Fnats-jwt-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseznam%2Fnats-jwt-py/lists"}