PageSourceSearch

https://keploy.io/docs/assets/js/f741c8b2.c9d41810.js

js keploy.io collected 2026-10-02 11:07:51 UTC 15,682 bytes, 2 lines download raw bytes

1"use strict";(globalThis.webpackChunkkeploy_docs=globalThis.webpackChunkkeploy_docs||[]).push([[4074],{10993(e,s,t){t.r(s),t.d(s,{assets:()=>p,contentTitle:()=>d,default:()=>u,frontMatter:()=>c,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"quickstart/flask-redis","title":"Sample Library App (Flask + Redis)","description":"This application is a simple Library API built using Flask and Redis for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records.","source":"@site/versioned_docs/version-4.0.0/quickstart/flask-redis.md","sourceDirName":"quickstart","slug":"/quickstart/flask-redis","permalink":"/docs/quickstart/flask-redis","draft":false,"unlisted":false,"editUrl":"https://github.com/keploy/docs/blob/master/versioned_docs/version-4.0.0/quickstart/flask-redis.md","tags":[{"inline":true,"label":"flask","permalink":"/docs/tags/flask"},{"inline":true,"label":"quickstart","permalink":"/docs/tags/quickstart"},{"inline":true,"label":"samples","permalink":"/docs/tags/samples"},{"inline":true,"label":"examples","permalink":"/docs/tags/examples"},{"inline":true,"label":"tutorial","permalink":"/docs/tags/tutorial"},{"inline":true,"label":"python-framework","permalink":"/docs/tags/python-framework"},{"inline":true,"label":"redis","permalink":"/docs/tags/redis"}],"version":"4.0.0","lastUpdatedBy":"Shubham Jain","lastUpdatedAt":1790780999000,"frontMatter":{"id":"flask-redis","title":"Sample Library App (Flask + Redis)","sidebar_label":"Flask + Redis","description":"This application is a simple Library API built using Flask and Redis for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records.","tags":["flask","quickstart","samples","examples","tutorial","python-framework","redis"],"keywords":["FastAPI Framework","Flask","Redis","Python","API Test generator","Auto case generation"]},"sidebar":"sidebarExplanation","previous":{"title":"Django + Postgres","permalink":"/docs/quickstart/samples-django"},"next":{"title":"E-commerce Microservices","permalink":"/docs/quickstart/samples-microservices"}}');var r=t(74848),a=t(28453),o=t(93303),l=t(12483),i=(t(28774),t(56764));const c={id:"flask-redis",title:"Sample Library App (Flask + Redis)",sidebar_label:"Flask + Redis",description:"This application is a simple Library API built using Flask and Redis for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records.",tags:["flask","quickstart","samples","examples","tutorial","python-framework","redis"],keywords:["FastAPI Framework","Flask","Redis","Python","API Test generator","Auto case generation"]},d=void 0,p={},h=[{value:"Get Started! \ud83c\udfac",id:"get-started-",level:3},{value:"Clone the application \ud83e\uddea",id:"clone-the-application-",level:3},{value:"Using Docker Compose \ud83d\udc33",id:"using-docker-compose-",level:2},{value:"Lights, Camera, Record! \ud83c\udfa5",id:"lights-camera-record-",level:3}
1,{value:"Generate testcases",id:"generate-testcases",level:3},{value:"<strong>Time to run the testcases</strong>",id:"time-to-run-the-testcases",level:3},{value:"Wrapping it up \ud83c\udf89",id:"wrapping-it-up-",level:3},{value:"Related",id:"related",level:2}];function m(e){const s={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(o.A,{name:"Sample Library App (Flask + Redis) \u2014 record and replay tests with Keploy",description:"Clone the sample app, run it under Keploy to capture API traffic, then replay the recorded testcases.",totalTime:"PT10M",estimatedCost:{currency:"USD",value:"0"},tools:["Keploy CLI","Docker","git"],visible:!1,steps:[{name:"Install Keploy",text:"Install the Keploy CLI: on Linux or macOS (Apple Silicon) with the install script from https://keploy.io/install.sh, or on Windows (x86-64) as keploy.exe from PowerShell (https://keploy.io/docs/installation/windows-installation/#option-1-run-keploy-natively). This sample runs under Docker Compose."},{name:"Clone the sample app",text:"Clone the sample repo referenced on this page and install its dependencies."},{name:"Start dependencies (database, etc.)",text:"Bring up any Docker services the app needs (databases, message queues) before recording."},{name:"Record API calls",text:'Run keploy record -c "CMD_TO_RUN_APP" and exercise the app\'s endpoints (curl, Postman) to capture testcases and mocks.'},{name:"Replay tests",text:'Run keploy test -c "CMD_TO_RUN_APP" --delay 10 to replay the recorded testcases and detect regressions.'}]}),"\n","\n",(0,r.jsx)(l.A,{tiers:"Enterprise",offerings:"Self-Hosted, Dedicated"}),"\n",(0,r.jsx)(s.p,{children:"\ud83e\ude84 Dive into the world of Student CRUD Apps and see how seamlessly Keploy integrated with Flask and Redis. Buckle up, it's gonna be a fun ride! \ud83c\udfa2"}),"\n","\n",(0,r.jsx)(i.A,{}),"\n",(0,r.jsx)(s.h3,{id:"get-started-",children:"Get Started! \ud83c\udfac"}),"\n",(0,r.jsx)(s.h3,{id:"clone-the-application-",children:"Clone the application \ud83e\uddea"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-redis\n"})}),"\n",(0,r.jsx)(s.h2,{id:"using-docker-compose-",children:"Using Docker Compose \ud83d\udc33"}),"\n",(0,r.jsx)(s.p,{children:"We will be using Docker compose to run the application as well as Mongo on Docker container."}),"\n",(0,r.jsx)(s.h3,{id:"lights-camera-record-",children:"Lights, Camera, Record! \ud83c\udfa5"}),"\n",(0,r.jsx)(s.p,{children:"Capture the test-cases-"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-shell",children:'keploy record -c "docker compose up" --container-name "flask-web" --buildDelay 50\n'})}),"\n",(0,r.jsxs)(s.p,{children:["\ud83d\udd25",(0,r.jsx)(s.strong,{children:"Make some API calls"}),". Postman, Hoppscotch or even curl - take your pick!"]}),"\n",(0,r.jsx)(s.p,{children:"Let's make URLs short and sweet:"}),"\n",(0,r.jsx)(s.h3,{id:"generate-testcases",children:"Generate testcases"}),"\n",(0,r.jsxs)(s.p,{children:["To generate testcases we just need to ",(0,r.jsx)(s.strong,{children:"make some API calls."})]}),"\n",(0,r.jsxs)(s.ol,{children:["\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.strong,{children:"Make a POST request:"})}),"\n"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:'curl -X POST http://localhost:5000/books/ \\\n-H "Content-Type: application/json" \\\n-d \'{"title": "1984", "author": "George Orwell"}\'\n'})}),"\n",(0,r.jsxs)(s.ol,{start:"2",children:["\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.strong,{children:"Make a GET request:"})}),"\n"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:'curl -X GET "http://localhost:5000/books/?page=1&limit=10"\n'})}),"\n",(0,r.jsxs)(s.ol,{start:"3",children:["\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.strong,{children:"Make a PUT request:"})}),"\n"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:'curl -X PUT http://localhost:5000/books/1 \\\n-H "Content-Type: application/json" \\\n-d \'{"title": "1984 - Updated", "author": "George Orwell"}\'\n'})}),"\n",(0,r.jsxs)(s.ol,{start:"4",children:["\n",(0,r.jsx)(s.li,{children:(0,r.jsx)(s.strong,{children:"Make a DELETE request:"})}),"\n"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"curl -X DELETE http://localhost:5000/books/1\n"})}),"\n",(0,r.jsxs)(s.p,{children:["And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the ",(0,r.jsx)(s.strong,{children:"keploy"})," directory and you'll discover your handiwork in ",(0,r.jsx)(s.code,{children:"tests"})," directory and ",(0,r.jsx)(s.code,{children:"mocks.yml"}),"."]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-yaml",children:'version: api.keploy.io/v1beta1\nkind: Redis\nname: mock-0\nspec:\n  metadata:\n    type: config\n  redisrequests:\n    - origin: client\n      message:\n        - type: string\n          data: "*4\\r\\n$6\\r\\nCLIENT\\r\\n$7\\r\\nSETINFO\\r\\n$8\\r\\nLIB-NAME\\r\\n$8\\r\\nredis-py\\r\\n"\n  redisresponses:\n    - origin: server\n      message:\n        - type: string\n          data: "+OK\\r\\n"\n  reqtimestampmock: 2024-08-02T22:15:10.6084523Z\n  restimestampmock: 2024-08-02T22:15:10.608930466Z\n---\n'})}),"\n",(0,r.jsx)(s.h3,{id:"time-to-run-the-testcases",children:(0,r.jsx)(s.strong,{children:"Time to run the testcases"})}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"keploy test -c 'sudo docker compose up' --containerName \"flask-web\" --delay 10\n"})}),"\n",(0,r.jsx)(s.p,{children:"You can also check the test summary from your cli"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:'<=========================================>\n  COMPLETE TESTRUN SUMMARY.\n        Total tests: 11\n        Total test passed: 10\n        Total test failed: 1\n        Total time taken: "15.13 s"\n\n        Test Suite Name         Total Test      Passed          Failed          Time Taken\n\n        "test-set-0"            6               6               0               "5.06 s"\n        "test-set-1"            1               1               0               "5.02 s"\n        "test-set-2"            4               3               1               "5.04 s"\n<=========================================>\n'})}),"\n",(0,r.jsx)(s.h3,{id:"wrapping-it-up-",children:"Wrapping it up \ud83c\udf89"}),"\n",(0,r.jsx)(s.p,{children:"Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible. \ud83d\ude0a\ud83d\ude80"}),"\n",(0,r.jsx)(s.h2,{id:"related",children:"Related"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"/docs/quickstart/python-filter/",children:"Sample Python Apps"})," \u2014 browse more Python samples."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"/docs/quickstart/samples-redis/",children:"Sample User Authentication App (Golang)"})," \u2014 another Redis-backed app."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"/docs/quickstart/samples-flask/",children:"Sample Task Creation CRUD App"})," \u2014 another Flask sample."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"/docs/quickstart/samples-fastapi/",children:"Sample Student Data CRUD App"})," \u2014 Python CRUD API."]}),"\n"]})]})}function u(e={}){const{wrapper:s}={...(0,a.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},56764(e,s,t){t.d(s,{A:()=>o});t(96540);var n=t(28774),r=t(95293),a=t(74848);function o(){const{colorMode:e}=(0,r.G)(),s="dark"===e,t={padding:"1rem",border:s?"1px solid #333":"1px solid #eee",borderRadius:"10px",background:s?"#23272f":"#fff8f5",margin:"2rem 0",color:s?"#fff":"#222",boxShadow:s?"0 2px 10px rgba(0,0,0,0.6)":"0 2px 6px rgba(0, 0, 0, 0.08)"};return(0,a.jsxs)("div",{style:t,children:[(0,a.jsx)("h3",{style:{marginTop:0,color:s?"#fff":"#222"},children:"Don\u2019t have Keploy installed yet?"}),(0,a.jsxs)("p",{style:{color:s?"#ccc":void 0},children:["Before running this sample, make sure Keploy is installed on your system and you\u2019re signed in to your Keploy account (",(0,a.jsx)("code",{children:"keploy login"}),")."]}),(0,a.jsx)(n.A,{to:"/docs/server/installation/",style:{display:"inline-block",marginTop:"0.5rem",padding:"0.6rem 1rem",background:"#e67e22",color:"#fff",borderRadius:"6px",fontWeight:"bold",textDecoration:"none"},children:"\ud83d\udc49 Go to Installation Guide"})]})}},93303(e,s,t){t.d(s,{A:()=>a});t(96540);
1var n=t(5260),r=t(74848);function a({name:e,description:s,totalTime:t,estimatedCost:a,tools:o,supplies:l,image:i,steps:c,visible:d=!0}){if(!e||!Array.isArray(c)||0===c.length)return null;const p=c.filter(e=>"string"==typeof e.name&&e.name.trim()&&"string"==typeof e.text&&e.text.trim());if(0===p.length)return null;const h={"@context":"https://schema.org","@type":"HowTo",name:e,step:p.map((e,s)=>{const t={"@type":"HowToStep",position:s+1,name:e.name,text:e.text};return e.url&&(t.url=e.url),e.image&&(t.image=e.image),t})};return s&&(h.description=s),t&&(h.totalTime=t),i&&(h.image=i),a&&void 0!==a.value&&(h.estimatedCost={"@type":"MonetaryAmount",currency:a.currency||"USD",value:String(a.value)}),Array.isArray(o)&&o.length>0&&(h.tool=o.map(e=>"string"==typeof e?{"@type":"HowToTool",name:e}:e)),Array.isArray(l)&&l.length>0&&(h.supply=l.map(e=>"string"==typeof e?{"@type":"HowToSupply",name:e}:e)),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.A,{children:(0,r.jsx)("script",{type:"application/ld+json",children:JSON.stringify(h)})}),d&&(0,r.jsxs)("section",{"aria-label":e,style:{border:"1px solid var(--ifm-color-emphasis-200)",borderRadius:"12px",padding:"1rem 1.25rem",margin:"1rem 0 1.5rem",background:"var(--ifm-background-surface-color)"},children:[(0,r.jsx)("h3",{style:{marginTop:0},children:e}),s&&(0,r.jsx)("p",{children:s}),(0,r.jsx)("ol",{children:p.map((e,s)=>(0,r.jsxs)("li",{children:[(0,r.jsx)("strong",{children:e.name}),(0,r.jsx)("div",{children:e.text})]},s))})]})]})}},12483(e,s,t){t.d(s,{A:()=>o});t(96540);var n=t(74848);const r={label:"Free",color:"#059669",bg:"rgba(16, 185, 129, 0.1)"},a={free:r,teams:{label:"Teams",color:"#0891b2",bg:"rgba(6, 182, 212, 0.1)"},scale:{label:"Scale",color:"#4f46e5",bg:"rgba(99, 102, 241, 0.1)"},enterprise:{label:"Enterprise",color:"#7c3aed",bg:"rgba(139, 92, 246, 0.1)"},"open source":r,oss:r,cloud:{label:"Cloud",color:"#2563eb",bg:"rgba(59, 130, 246, 0.1)"},"self-hosted":{label:"Self-Hosted",color:"#6b7280",bg:"rgba(107, 114, 128, 0.08)"},dedicated:{label:"Dedicated",color:"#6b7280",bg:"rgba(107, 114, 128, 0.08)"},local:{label:"Local",color:"#6b7280",bg:"rgba(107, 114, 128, 0.08)"}},o=({tiers:e,offerings:s})=>{const t=[...e?Array.isArray(e)?e:e.split(",").map(e=>e.trim()):[],...s?Array.isArray(s)?s:s.split(",").map(e=>e.trim()):[]];return 0===t.length?null:(0,n.jsxs)("div",{className:"product-tier-chips",children:[t.map((e,s)=>{const t=e.toLowerCase().trim(),r=a[t]||{label:e.trim(),color:"#6b7280",bg:"rgba(107, 114, 128, 0.08)"};return(0,n.jsx)("span",{className:"product-tier-chip",style:{color:r.color,background:r.bg},children:r.label},s)}),(0,n.jsx)("style",{children:'\n        .product-tier-chips {\n          display: inline-flex;\n          flex-wrap: wrap;\n          gap: 0.375rem;\n          margin-bottom: 0;\n        }\n        .product-tier-chip {\n          display: inline-flex;\n          align-items: center;\n          padding: 0.1875rem 0.5rem;\n          font-size: 0.6875rem;\n          font-weight: 600;\n          border-radius: 4px;\n          white-space: nowrap;\n          letter-spacing: 0.01em;\n        }\n        html[data-theme="dark"] .product-tier-chip {\n          background: rgba(255, 255, 255, 0.15) !important;\n        }\n      '})]})}},28453(e,s,t){t.d(s,{R:()=>o,x:()=>l});var n=t(96540);const r={},a=n.createContext(r);function o(e){const s=n.useContext(a);return n.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),n.createElement(a.Provider,{value:s},e.children)}}}]);
2//# sourceMappingURL=f741c8b2.c9d41810.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.