PropelAuth Python velease
Today, we are excited to release a new version of our base Python library, as well as releases of our framework-specific libraries for FastAPI, Flask, and Django Rest Framework.
Let’s jump in to some of the larger changes!
Better Typing Support (breaking change)
If you’ve used our Python libraries before, the type hinting left a lot to be desired. In our latest release, we now have type hints for all requests as well as datatypes for all responses.
NOTE: This will break specifically if you were previously unpacking (using the ** operator) on responses. Responses were previously dicts and are now explicit datatypes.
We have implemented commonly used functions like a key lookup (response["user_id"] will still work, but response.user_id is now preferred). We typically try to avoid breaking changes (this is our second in 3 years), but this felt like a pretty narrow problem.
User class improvements
For simpler permissions checking, you can now call functions directly on the User object like:
- user.has_permission_in_org(orgId, 'can_export_reports')
- user.is_role(orgId, 'Admin')
- user.get_active_org().has_permission('api_key::write')
These allow you to pass around the User object instead of needing to refer back to the Auth object, and it also allows for easier mocking/testing.
New APIs
This isn’t specific to our Python library, but we’ve released a lot of new APIs like:
- Force logout all user sessions
- Creating a SAML setup link for your customer (which will let them manage SAML themselves)
- Fetching and revoking pending invites
- Support for legacy_org_id which can help you migrate from your existing setup
See the full list in our reference docs here.
Example - Easy feature gating by pricing plan
At PropelAuth, we’ve been fortunate to have a front-row seat to seeing many B2B SaaS companies grow. Auth providers are most important at critical moments in a company's history (initial launch, onboarding your first customer, closing your first enterprise customer, etc.). The most important thing we can do as you grow is to get out of the way.
That’s why we’re really happy with this FastAPI route:
@app.post("/api/expensive-action") async def do_expensive_action(user: User = Depends(auth.require_user)): org = user.get_active_org() if org == None or \ not org.user_has_permission("can_do_expensive_action"): raise HTTPException(status_code=403, detail="Forbidden") return do_expensive_action_inner(user, org)
At first glance, this seems like a pretty simple route, but it has a few important pieces:
- The dependency injected User works with any type of authenticated user - whether it’s password, SSO, SAML, etc.
- With role mappings, we can make it so an Admin of an org on our Free plan can not do the expensive feature, but an Admin of an org on our Paid plans can do the expensive action.
- We can enforce that programmatically by handling a webhook from our payment provider and setting their role mapping, like so:
@app.post("/api/expensive-action") async def do_expensive_action(user: User = Depends(auth.require_user)): org = user.get_active_org() if org == None or \ not org.user_has_permission("can_do_expensive_action"): raise HTTPException(status_code=403, detail="Forbidden") return do_expensive_action_inner(user, org)
- We can even give them self-serve access to advanced features like SAML and SCIM by programmatically generating a SAML connection URL, which will guide your user through setting up those features - with specific instructions for each identity provider (Okta, Azure AD, ADFS, etc.).
And the best part? That same code snippet above will continue to work. Even as our customer’s requirements get more complicated, your code won’t.
Questions? Feedback?
We're always looking to improve our libraries and services based on your feedback. If you have any questions about this release or suggestions for future improvements, please don't hesitate to reach out.
The above is the detailed content of PropelAuth Python velease. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.
