{"id":19476492,"url":"https://github.com/frankkkkk/pykorm","last_synced_at":"2025-04-25T14:32:17.628Z","repository":{"id":40547604,"uuid":"277898655","full_name":"Frankkkkk/pykorm","owner":"Frankkkkk","description":"A python 🐍 kubernetes ☸️ ORM  🚀. Very useful when writing  operators for your CRDs with Kopf.","archived":false,"fork":false,"pushed_at":"2023-02-08T03:08:42.000Z","size":220,"stargazers_count":73,"open_issues_count":12,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-20T13:58:34.789Z","etag":null,"topics":["crd","customresourcedefinition","kopf","kubernetes","object","orm","pykube","python","python-kubernetes","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Frankkkkk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-07T18:56:43.000Z","updated_at":"2025-04-14T03:57:29.000Z","dependencies_parsed_at":"2023-02-09T13:31:23.800Z","dependency_job_id":null,"html_url":"https://github.com/Frankkkkk/pykorm","commit_stats":{"total_commits":63,"total_committers":7,"mean_commits":9.0,"dds":"0.23809523809523814","last_synced_commit":"7594a37889bd9a896044139f1f545fe8d516878e"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frankkkkk%2Fpykorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frankkkkk%2Fpykorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frankkkkk%2Fpykorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frankkkkk%2Fpykorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Frankkkkk","download_url":"https://codeload.github.com/Frankkkkk/pykorm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250834158,"owners_count":21494920,"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","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":["crd","customresourcedefinition","kopf","kubernetes","object","orm","pykube","python","python-kubernetes","sqlalchemy"],"created_at":"2024-11-10T19:40:30.697Z","updated_at":"2025-04-25T14:32:16.052Z","avatar_url":"https://github.com/Frankkkkk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pykorm - Python Kubernetes Object-relational mapping (ORM)\n\n`pykorm` is a simple library that links your models to their `kubernetes` counterpart.\n\nEach model and instance on your code is thus directly linked to your kubernetes\ncluster and modifications are thus reflected both ways.\n\n# Examples\n## Namespaced Custom Resource\n### Setup\nFirst of all, you need to have Custom Resource Definitions on your cluster.  \nThis README will use the following Namespaced resource. You can apply it on your \ncluster with `kubectl`.\n\n```yaml\napiVersion: apiextensions.k8s.io/v1\nkind: CustomResourceDefinition\nmetadata:\n  name: peaches.pykorm.infomaniak.com\nspec:\n  group: pykorm.infomaniak.com\n  names:\n    kind: Peach\n    listKind: PeachList\n    plural: peaches\n    singular: peach\n  scope: Namespaced\n  versions:\n  - name: v1\n    served: true\n    storage: true\n    schema:\n      openAPIV3Schema:\n        type: object\n        properties:\n          spec:\n            type: object\n            properties:\n              variety:\n                type: string\n            required:\n              - variety\n\n\n    additionalPrinterColumns:\n    - name: Variety\n      type: string\n      description: The variety of the peach\n      jsonPath: .spec.variety\n```\n\n### Class definition\nIn order to link a python class to a kubernetes CustomResourceDefinition,\nyou need to inherit the class from pykorm's `NamespacedModel` or `ClusterModel` \nand annotate it with the kubernetes CRD information like so:\n```python\nimport pykorm\n\n@pykorm.k8s_custom_object('pykorm.infomaniak.com', 'v1', 'peaches')\nclass Peach(pykorm.NamespacedModel):\n    variety: str = pykorm.fields.Spec('variety')\n```\n\nNotice that a class inheriting from `pykorm.NamespacedModel` already has the \n`name` and `namespace` fields setup.\n\n### Create a CR\nIn order to create a kubernetes custom resource from python, you just\nhave to instantiate the class and save it with `Pykorm.save()`:\n```python\nimport pykorm\npk = pykorm.Pykorm()\n\ncake_peach = Peach(namespace='default', name='cake-peach', variety='Frost')\npk.save(cake_peach)  # We save the resource\n```\nas you can see, the model is instantly ensured in kubernetes:\n```bash\n$ kubectl get peach -n default\nNAME         VARIETY\ncake-peach   Frost\n```\n\n### List resources\nPykorm can also list resources from kubernetes\n```python\n\u003e\u003e\u003e all_peaches = Peach.query.all()\n\u003e\u003e\u003e for peach in all_peaches:\n\u003e\u003e\u003e  print(peach)\n\u003cPeach namespace=default, name=cake-peach, variety=Frost\u003e\n\n# Filter by namespace\n\u003e\u003e\u003e Peach.query.filter_by(namespace='default').filter_by(variety='Frost').all()\n```\n\nYou can even filter resources by some criterion:\n```python\n\u003e\u003e\u003e Peach.query.filter_by(name='cake-peach').all()\n[\u003cPeach namespace=default, name=cake-peach, variety=Frost\u003e]\n\u003e\u003e\u003e Peach.query.filter_by(namespace='kube-system').all()\n[]\n```\n\n### Delete resources\nYou can delete a resource with `pykorm` too:\n```python\npk.delete(peach)\n```\n```bash\n$ kubectl get peach\nNo resources found in default namespace.\n```\n\n## More examples\nFor more examples, don't hesitate to look into the `examples/` directory\n\n* [CoreAPI Wrapper](./examples/core_api.py)\n* [Multi Layer Nested \u0026 Mixin Fields](./examples/nested_example.py)\n* [Label Filter \u0026 Field Selector](./examples/filter_example.py)\n* [Multi Cluster](./examples/multi_cluster_example.py)\n\n\n# Is pykorm stable ?\npykorm is still very young and very naive. It's also missing quite a lot of \nfeatures (relationships, etc.).\nIt was originally created because a lot of boilerplate code was written each\ntime a kubernetes custom object had to be interfaced with python \ncode.\n\nWork on `pykorm` is actually on the way. Don't hesitate to contribute to the \nproject if you have the energy for it !\n\n\n\n## Equivalences\n| Python   | Kubernetes  |\n|----------|-------------|\n| Class    | CustomResourceDefinition |\n| Instance | CustomResource |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankkkkk%2Fpykorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrankkkkk%2Fpykorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankkkkk%2Fpykorm/lists"}